https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80121
janus at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |janus at gcc dot gnu.org
--- Comment #9 from janus at gcc dot gnu.org ---
(In reply to janus from comment #7)
> My feeling is that it would be a good idea to handle allocatable derived
> types inside of the callee as well.
Disregarding any refactoring plans for now, here if a first simple draft patch:
Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c (revision 247077)
+++ gcc/fortran/trans-expr.c (working copy)
@@ -5454,6 +5454,16 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol *
if (fsym && fsym->attr.allocatable
&& fsym->attr.intent == INTENT_OUT)
{
+ if (fsym->ts.type == BT_DERIVED
+ && fsym->ts.u.derived->attr.alloc_comp)
+ {
+ // deallocate the components first
+ tmp = gfc_deallocate_alloc_comp (fsym->ts.u.derived,
+ parmse.expr, e->rank);
+ if (tmp != NULL_TREE)
+ gfc_add_expr_to_block (&se->pre, tmp);
+ }
+
tmp = build_fold_indirect_ref_loc (input_location,
parmse.expr);
if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)))
This seems to be sufficient to fix the memory leaks for the test cases in
comment 0 and comment 3. Regtesting now ...