http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41936
Mikael Morin <mikael at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch CC| |mikael at gcc dot gnu.org --- Comment #2 from Mikael Morin <mikael at gcc dot gnu.org> 2011-02-28 21:22:39 UTC --- Fixed if one adds the code below (copied from gfc_conv_array_parameter). I'm afraid this could change a memory leak into a double free (see PR 40850). Also, not quite right (even if the middle-end optimizers are likely to fix it) because it adds cleanup code to both foo and bar. diff --git a/trans-expr.c b/trans-expr.c index d6c1f9f..3919870 100644 --- a/trans-expr.c +++ b/trans-expr.c @@ -4900,6 +4900,19 @@ gfc_conv_expr_reference (gfc_se * se, gfc_expr * expr) /* Take the address of that value. */ se->expr = gfc_build_addr_expr (NULL_TREE, var); + if ((expr->ts.type == BT_DERIVED || expr->ts.type == BT_CLASS) + && expr->ts.u.derived->attr.alloc_comp + && expr->expr_type != EXPR_VARIABLE) + { + tree tmp; + + tmp = build_fold_indirect_ref_loc (input_location, se->expr); + tmp = gfc_deallocate_alloc_comp (expr->ts.u.derived, tmp, expr->rank); + + /* The components shall be deallocated before + their containing entity. */ + gfc_prepend_expr_to_block (&se->post, tmp); + } }