This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, Fortran] PR58436 - Fix a CLASS(*) finalization bug


I forgot, again, to attach the patch.

However, to my surprise the email made it through. Contrary to Janus' second patch review of today which didn't went past GCC's mail server. (The same problem I had yesterday: Three emails didn't make it.)

Tobias Burnus wrote:
There were two related issues with the _vtab of CLASS(*): First, it was crashing in the generation of the finalization wrapper. Secondly, one needs to ensure that the _vtab contains a NULL pointer for _final.

Build and regtested on x86-64-gnu-linux.
OK for the trunk?

Tobias

diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c
index 7117e83..be4959a 100644
--- a/gcc/fortran/class.c
+++ b/gcc/fortran/class.c
@@ -1427,6 +1427,12 @@ generate_finalization_wrapper (gfc_symbol *derived, gfc_namespace *ns,
   gfc_expr *ancestor_wrapper = NULL, *rank;
   gfc_iterator *iter;
 
+  if (derived->attr.unlimited_polymorphic)
+    {
+      vtab_final->initializer = gfc_get_null_expr (NULL);
+      return;
+    }
+
   /* Search for the ancestor's finalizers. */
   if (derived->attr.extension && derived->components
       && (!derived->components->ts.u.derived->attr.abstract
diff --git a/gcc/testsuite/gfortran.dg/finalize_21.f90 b/gcc/testsuite/gfortran.dg/finalize_21.f90
new file mode 100644
index 0000000..6f6ede3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/finalize_21.f90
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+!
+! PR fortran/58436
+!
+! The following was ICEing and lacking _final=0
+!
+class(*), allocatable :: var
+end
+
+! { dg-final { scan-tree-dump "static struct __vtype__STAR __vtab__STAR = {._hash=0, ._size=., ._extends=0B, ._def_init=0B, ._copy=0B, ._final=0B};" "original" } }
+! { dg-final { cleanup-tree-dump "original" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]