https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127728

--- Comment #2 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
Can you test this:

diff --git a/gcc/fortran/class.cc b/gcc/fortran/class.cc
index faca0b877d0..e4f122d7688 100644
--- a/gcc/fortran/class.cc
+++ b/gcc/fortran/class.cc
@@ -1084,8 +1084,18 @@ finalize_component (gfc_expr *expr, gfc_symbol *derived,
gfc_component *comp,
       ref->next->u.ar.type = e->rank ? AR_FULL : AR_ELEMENT;
     }

+  /* A nonallocatable array of a nonfinalizable derived type is deallocated
+     as a whole, rather than once per allocatable component.  */
+  bool whole_array = (comp->ts.type == BT_DERIVED
+                     && comp->attr.dimension
+                     && !comp->attr.allocatable
+                     && comp->ts.u.derived->attr.alloc_comp
+                     && !comp->ts.u.derived->attr.pdt_type
+                     && !comp->ts.u.derived->attr.pdt_comp
+                     && !gfc_is_finalizable (comp->ts.u.derived, NULL));
+
   /* Call DEALLOCATE (comp, stat=ignore).  */
-  if (comp->attr.allocatable
+  if (comp->attr.allocatable || whole_array
       || (comp->ts.type == BT_CLASS && CLASS_DATA (comp)
          && CLASS_DATA (comp)->attr.allocatable))
     {

I have not run the full testsuite yet

Reply via email to