From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2726 invoked by alias); 4 May 2014 10:06:43 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 2658 invoked by uid 48); 4 May 2014 10:06:39 -0000 From: "dominiq at lps dot ens.fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/41936] Memory leakage with allocatables and user-defined operators Date: Sun, 04 May 2014 10:06:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 4.5.0 X-Bugzilla-Keywords: patch, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: dominiq at lps dot ens.fr X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: pault at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-05/txt/msg00181.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41936 --- Comment #6 from Dominique d'Humieres --- Is the following patch OK? --- ../_clean/gcc/fortran/trans-expr.c 2014-04-30 21:41:33.000000000 +0200 +++ gcc/fortran/trans-expr.c 2014-05-04 00:42:50.000000000 +0200 @@ -6504,6 +6504,20 @@ gfc_conv_expr_reference (gfc_se * se, gf /* Take the address of that value. */ se->expr = gfc_build_addr_expr (NULL_TREE, var); + if (expr->ts.type == BT_DERIVED && expr->rank + && !gfc_is_finalizable (expr->ts.u.derived, NULL) + && 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); + } } It fixes the memory leaks for the test in comment 0 and for gfortran.dg/class_array_15.f03, but not pr55603 nor pr60913. Is the following change for gfortran.dg/class_array_15.f03 --- ../_clean/gcc/testsuite/gfortran.dg/class_array_15.f03 2013-01-06 22:34:50.000000000 +0100 +++ gcc/testsuite/gfortran.dg/class_array_15.f03 2014-05-04 10:24:06.000000000 +0200 @@ -1,4 +1,5 @@ ! { dg-do run } +! { dg-options "-fdump-tree-original" } ! ! Tests the fixes for three bugs with the same underlying cause. All are regressions ! that come about because class array elements end up with a different tree type @@ -114,3 +115,5 @@ subroutine pr54992 ! This test remains bh => bhGet(b,instance=2) if (loc (b) .ne. loc(bh%hostNode)) call abort end +! { dg-final { scan-tree-dump-times "builtin_free" 12 "original" } } +! { dg-final { cleanup-tree-dump "original" } } enough (there are only 11 builtin_free without the patch)? or should I add the test in comment 0 (15 builtin_free with the patch, 12 without)?