aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDominique d'Humieres <dominiq@lps.ens.fr>2014-06-10 13:42:38 +0200
committerDominique d'Humieres <dominiq@gcc.gnu.org>2014-06-10 13:42:38 +0200
commit5933f9ae4f8d7b9dec44ec95e70fcc543a616839 (patch)
tree2441a277b636ff7fa134f35b5860ed41ba4af0ec /gcc
parent5625721fbbf403e891fd6988bdf62fa0ad24c6be (diff)
downloadgcc-5933f9ae4f8d7b9dec44ec95e70fcc543a616839.zip
gcc-5933f9ae4f8d7b9dec44ec95e70fcc543a616839.tar.gz
gcc-5933f9ae4f8d7b9dec44ec95e70fcc543a616839.tar.bz2
re PR fortran/41936 (Memory leakage with allocatables and user-defined operators)
2014-06-10 Dominique d'Humieres <dominiq@lps.ens.fr> Mikael Morin <mikael@gcc.gnu.org> PR fortran/41936 gcc/fortran/ * trans-expr.c (gfc_conv_expr_reference): Deallocate array components. gcc/testsuite/ * gfortran.dg/class_array_15.f03: Check memory leaks. Co-Authored-By: Mikael Morin <mikael@gcc.gnu.org> From-SVN: r211405
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/trans-expr.c14
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gfortran.dg/class_array_15.f033
4 files changed, 30 insertions, 0 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index f945dd1..bdc102b 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,10 @@
+2014-06-10 Dominique d'Humieres <dominiq@lps.ens.fr>
+ Mikael Morin <mikael@gcc.gnu.org>
+
+ PR fortran/41936
+ * trans-expr.c (gfc_conv_expr_reference): Deallocate array
+ components.
+
2014-06-10 Jakub Jelinek <jakub@redhat.com>
PR fortran/60928
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 5a50122..5338b09 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -6506,6 +6506,20 @@ 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->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);
+ }
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e86cb9b..175bbeb 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2014-06-10 Dominique d'Humieres <dominiq@lps.ens.fr>
+ Mikael Morin <mikael@gcc.gnu.org>
+
+ PR fortran/41936
+ * gfortran.dg/class_array_15.f03: Check memory leaks.
+
2014-06-10 Richard Biener <rguenther@suse.de>
PR tree-optimization/57186
diff --git a/gcc/testsuite/gfortran.dg/class_array_15.f03 b/gcc/testsuite/gfortran.dg/class_array_15.f03
index 7d1d4d7..d3a1232 100644
--- a/gcc/testsuite/gfortran.dg/class_array_15.f03
+++ b/gcc/testsuite/gfortran.dg/class_array_15.f03
@@ -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 as the original.
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" } }