re PR fortran/79311 ([OOP] ICE in generate_finalization_wrapper, at fortran/class...
authorJanus Weil <janus@gcc.gnu.org>
Tue, 9 May 2017 20:55:38 +0000 (22:55 +0200)
committerJanus Weil <janus@gcc.gnu.org>
Tue, 9 May 2017 20:55:38 +0000 (22:55 +0200)
2017-05-09  Janus Weil  <janus@gcc.gnu.org>

PR fortran/79311
* resolve.c (gfc_resolve_finalizers): Ensure that derived-type
components have a their finalizers resolved, also if the superordinate
type itself has a finalizer.

2017-05-09  Janus Weil  <janus@gcc.gnu.org>

PR fortran/79311
* gfortran.dg/finalize_32.f90: New test.

From-SVN: r247818

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/finalize_32.f90 [new file with mode: 0644]

index 1803789967cec51615afb0fca140a6b2eb1864f7..98c499070d5c68a174f25b3b5e46f273f1de6255 100644 (file)
@@ -1,3 +1,10 @@
+2017-05-09  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/79311
+       * resolve.c (gfc_resolve_finalizers): Ensure that derived-type
+       components have a their finalizers resolved, also if the superordinate
+       type itself has a finalizer.
+
 2017-05-08  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/79930
index 565e02b534b504c72aa47df9e2845dca5f3ad509..df32a8a853990d95734fa8f16106ffb03f696945 100644 (file)
@@ -12385,26 +12385,23 @@ gfc_resolve_finalizers (gfc_symbol* derived, bool *finalizable)
   if (parent)
     gfc_resolve_finalizers (parent, finalizable);
 
-  /* Return early when not finalizable. Additionally, ensure that derived-type
-     components have a their finalizables resolved.  */
-  if (!derived->f2k_derived || !derived->f2k_derived->finalizers)
-    {
-      bool has_final = false;
-      for (c = derived->components; c; c = c->next)
-       if (c->ts.type == BT_DERIVED
-           && !c->attr.pointer && !c->attr.proc_pointer && !c->attr.allocatable)
-         {
-           bool has_final2 = false;
-           if (!gfc_resolve_finalizers (c->ts.u.derived, &has_final))
-             return false;  /* Error.  */
-           has_final = has_final || has_final2;
-         }
-      if (!has_final)
-       {
-         if (finalizable)
-           *finalizable = false;
-         return true;
-       }
+  /* Ensure that derived-type components have a their finalizers resolved.  */
+  bool has_final = derived->f2k_derived && derived->f2k_derived->finalizers;
+  for (c = derived->components; c; c = c->next)
+    if (c->ts.type == BT_DERIVED
+       && !c->attr.pointer && !c->attr.proc_pointer && !c->attr.allocatable)
+      {
+       bool has_final2 = false;
+       if (!gfc_resolve_finalizers (c->ts.u.derived, &has_final2))
+         return false;  /* Error.  */
+       has_final = has_final || has_final2;
+      }
+  /* Return early if not finalizable.  */
+  if (!has_final)
+    {
+      if (finalizable)
+       *finalizable = false;
+      return true;
     }
 
   /* Walk over the list of finalizer-procedures, check them, and if any one
index 5906d94e25d887ba49fa51e5fa057879cec5de7d..b9b01f887c8230d4efece5b1376ef5a108e1fa88 100644 (file)
@@ -1,3 +1,8 @@
+2017-05-09  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/79311
+       * gfortran.dg/finalize_32.f90: New test.
+
 2017-05-09  Volker Reichelt  <v.reichelt@netcologne.de>
 
        PR c/35441
diff --git a/gcc/testsuite/gfortran.dg/finalize_32.f90 b/gcc/testsuite/gfortran.dg/finalize_32.f90
new file mode 100644 (file)
index 0000000..45fb7c1
--- /dev/null
@@ -0,0 +1,31 @@
+! { dg-do compile }
+!
+! PR 79311: [OOP] ICE in generate_finalization_wrapper, at fortran/class.c:1992
+!
+! Contributed by DIL <liakhdi@ornl.gov>
+
+module tensor_recursive
+  implicit none
+
+  type :: tens_signature_t
+  contains
+    final :: tens_signature_dtor
+  end type
+
+  type :: tens_header_t
+    type(tens_signature_t) :: signature
+  contains
+    final :: tens_header_dtor
+  end type
+
+contains
+
+  subroutine tens_signature_dtor(this)
+    type(tens_signature_t) :: this
+  end subroutine
+
+  subroutine tens_header_dtor(this)
+    type(tens_header_t) :: this
+  end subroutine
+
+end