http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59781

--- Comment #5 from janus at gcc dot gnu.org ---
Here is a draft patch which seems to fix comment 1 to 3:


Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c    (revision 206579)
+++ gcc/fortran/trans-decl.c    (working copy)
@@ -4005,8 +4005,6 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gf
     }
       else if (sym->ts.deferred)
     gfc_fatal_error ("Deferred type parameter not yet supported");
-      else if (alloc_comp_or_fini)
-    gfc_trans_deferred_array (sym, block);
       else if (sym->ts.type == BT_CHARACTER)
     {
       gfc_save_backend_locus (&loc);
@@ -4017,6 +4015,18 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gf
         gfc_trans_auto_character_variable (sym, block);
       gfc_restore_backend_locus (&loc);
     }
+      else if (sym->ts.type == BT_DERIVED)
+    {
+      if (alloc_comp_or_fini)
+        gfc_trans_deferred_array (sym, block);
+      if (sym->value && !sym->attr.data && sym->attr.save == SAVE_NONE)
+        {
+          gfc_start_block (&tmpblock);
+          gfc_init_default_dt (sym, &tmpblock, false);
+          gfc_add_init_cleanup (block, gfc_finish_block (&tmpblock),
+                    NULL_TREE);
+        }
+    }
       else if (sym->attr.assign)
     {
       gfc_save_backend_locus (&loc);
@@ -4024,16 +4034,6 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gf
       gfc_trans_assign_aux_var (sym, block);
       gfc_restore_backend_locus (&loc);
     }
-      else if (sym->ts.type == BT_DERIVED
-         && sym->value
-         && !sym->attr.data
-         && sym->attr.save == SAVE_NONE)
-    {
-      gfc_start_block (&tmpblock);
-      gfc_init_default_dt (sym, &tmpblock, false);
-      gfc_add_init_cleanup (block, gfc_finish_block (&tmpblock),
-                NULL_TREE);
-    }
       else if (!(UNLIMITED_POLY(sym)))
     gcc_unreachable ();
     }


I have not regtested it yet. One minor remaining problem is that the
allocatable component is nullified twice now.

Reply via email to