aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/trans-expr.c
diff options
context:
space:
mode:
authorJanus Weil <janus@gcc.gnu.org>2017-04-23 10:26:50 +0200
committerJanus Weil <janus@gcc.gnu.org>2017-04-23 10:26:50 +0200
commit60fc41bd415a631d7db82d56ed44d95677edf57e (patch)
treea557d19859ebe646e286f5d60c01354838eb4ffe /gcc/fortran/trans-expr.c
parent2eb8a34363025d04482a798dec1c885e1e3a3803 (diff)
downloadgcc-60fc41bd415a631d7db82d56ed44d95677edf57e.zip
gcc-60fc41bd415a631d7db82d56ed44d95677edf57e.tar.gz
gcc-60fc41bd415a631d7db82d56ed44d95677edf57e.tar.bz2
re PR fortran/80121 (Memory leak with derived-type intent(out) argument)
2017-04-22 Janus Weil <janus@gcc.gnu.org> PR fortran/80121 * trans-types.c (gfc_conv_procedure_call): Deallocate the components of allocatable intent(out) arguments. 2017-04-22 Janus Weil <janus@gcc.gnu.org> PR fortran/80121 * gfortran.dg/intent_out_9.f90: New test case. From-SVN: r247083
Diffstat (limited to 'gcc/fortran/trans-expr.c')
-rw-r--r--gcc/fortran/trans-expr.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 7bced25..af1549a 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -5454,6 +5454,16 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
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)))