aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Burnus <burnus@net-b.de>2012-05-23 19:13:27 +0000
committerTobias Burnus <burnus@net-b.de>2012-05-23 19:13:27 +0000
commitf6182a99f40eacd2d60762b8ab74a357f6d4cc09 (patch)
tree2b09d2a3c7d44ab2c932bde6859ad708040fea11
parent4c3d484d3a35c57be0a2e235d05ef1fbd96ace85 (diff)
2012-05-23 Tobias Burnus <burnus@net-b.de>
PR fortran/53389 * trans-array.c (gfc_add_loop_ss_code): Don't evaluate expression, if ss->is_alloc_lhs is set. 2012-05-23 Tobias Burnus <burnus@net-b.de> PR fortran/53389 * gfortran.dg/realloc_on_assign_15.f90: New. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@187810 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/fortran/ChangeLog6
-rw-r--r--gcc/fortran/trans-array.c5
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/realloc_on_assign_15.f9040
4 files changed, 56 insertions, 0 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index b5789984b5f..e9d912eb6cf 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,9 @@
+2012-05-23 Tobias Burnus <burnus@net-b.de>
+
+ PR fortran/53389
+ * trans-array.c (gfc_add_loop_ss_code): Don't evaluate
+ expression, if ss->is_alloc_lhs is set.
+
2012-05-02 Tobias Burnus <burnus@net-b.de>
Backport from mainline
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index a4be6e7b165..d0d0900eb1d 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -2056,6 +2056,11 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, bool subscript,
gfc_se se;
int n;
+ /* Don't evaluate the arguments for realloc_lhs_loop_for_fcn_call; otherwise,
+ arguments could get evaluated multiple times. */
+ if (ss->is_alloc_lhs)
+ return;
+
/* TODO: This can generate bad code if there are ordering dependencies,
e.g., a callee allocated function and an unknown size constructor. */
gcc_assert (ss != NULL);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7e11c70fe82..e342cb81f84 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2012-05-23 Tobias Burnus <burnus@net-b.de>
+
+ PR fortran/53389
+ * gfortran.dg/realloc_on_assign_15.f90: New.
+
2012-05-22 Richard Guenther <rguenther@suse.de>
Backport from mainline
diff --git a/gcc/testsuite/gfortran.dg/realloc_on_assign_15.f90 b/gcc/testsuite/gfortran.dg/realloc_on_assign_15.f90
new file mode 100644
index 00000000000..2a0e5be9101
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/realloc_on_assign_15.f90
@@ -0,0 +1,40 @@
+! { dg-do run }
+!
+! PR fortran/53389
+!
+! The program was leaking memory before due to
+! realloc on assignment and nested functions.
+!
+module foo
+ implicit none
+ contains
+
+ function filler(array, val)
+ real, dimension(:), intent(in):: array
+ real, dimension(size(array)):: filler
+ real, intent(in):: val
+
+ filler=val
+
+ end function filler
+end module
+
+program test
+ use foo
+ implicit none
+
+ real, dimension(:), allocatable:: x, y
+ integer, parameter:: N=1000 !*1000
+ integer:: i
+
+! allocate( x(N) )
+ allocate( y(N) )
+ y=0.0
+
+ do i=1, N
+! print *,i
+ x=filler(filler(y, real(2*i)), real(i))
+ y=y+x
+ end do
+
+end program test