]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix regtest failure in pdt_48.f03. [PR83746]
authorPaul Thomas <pault@gcc.gnu.org>
Sat, 20 Sep 2025 13:25:47 +0000 (14:25 +0100)
committerPaul Thomas <pault@gcc.gnu.org>
Sat, 20 Sep 2025 13:25:47 +0000 (14:25 +0100)
2025-09-20  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/83746
* trans-decl.cc (gfc_trans_deferred_vars): If a procedure with
an non-allocatable, non-pointer explicit PDT result has no
default initializer, the parameterized components should be
allocated.

gcc/fortran/trans-decl.cc

index f423dd728aaa6685b78aabd1f0fc9be95ee08ad3..055698b1efdbbf140cc67569ae4e5173c81f0f65 100644 (file)
@@ -4831,6 +4831,23 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
        }
     }
 
+  sym = (proc_sym->attr.function
+        && proc_sym != proc_sym->result) ? proc_sym->result : NULL;
+
+  if (sym && !sym->attr.allocatable && !sym->attr.pointer
+      && sym->ts.type == BT_DERIVED
+      && sym->ts.u.derived
+      && !gfc_has_default_initializer (sym->ts.u.derived)
+      && sym->ts.u.derived->attr.pdt_type)
+    {
+      gfc_init_block (&tmpblock);
+      tmp = gfc_allocate_pdt_comp (sym->ts.u.derived,
+                                  sym->backend_decl,
+                                  sym->as ? sym->as->rank : 0,
+                                  sym->param_list);
+      gfc_add_expr_to_block (&tmpblock, tmp);
+      gfc_add_init_cleanup (block, gfc_finish_block (&tmpblock), NULL);
+    }
 
   /* Initialize the INTENT(OUT) derived type dummy arguments.  This
      should be done here so that the offsets and lbounds of arrays