From 9e64f226249f0d6e934af1cde7968becd1669587 Mon Sep 17 00:00:00 2001 From: burnus Date: Tue, 22 May 2012 10:10:47 +0000 Subject: [PATCH] 2012-05-22 Tobias Burnus PR fortran/53389 * trans-array.c (gfc_add_loop_ss_code): Don't evaluate * expression, if ss->is_alloc_lhs is set. 2012-05-22 Tobias Burnus PR fortran/53389 * gfortran.dg/realloc_on_assign_15.f90: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@187769 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 8 ++++- gcc/fortran/trans-array.c | 5 +++ gcc/testsuite/ChangeLog | 7 +++- gcc/testsuite/gfortran.dg/realloc_on_assign_15.f90 | 40 ++++++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/realloc_on_assign_15.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 0880b31..38bff78 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,8 +1,14 @@ +2012-05-22 Tobias Burnus + + PR fortran/53389 + * trans-array.c (gfc_add_loop_ss_code): Don't evaluate expression, if + ss->is_alloc_lhs is set. + 2012-05-22 Dodji Seketeli PR c++/53322 * f95-lang.c (gfc_init_builtin_functions): Remove the unused - typedef builtin_type. + typedef builtin_type. 2012-05-14 Janne Blomqvist diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index b24d1c3..02bb38d 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -2401,6 +2401,11 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, bool subscript, bool skip_nested = false; 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; + outer_loop = outermost_loop (loop); /* TODO: This can generate bad code if there are ordering dependencies, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0d21111..21f448d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-05-22 Tobias Burnus + + PR fortran/53389 + * gfortran.dg/realloc_on_assign_15.f90: New. + 2012-05-22 Richard Guenther PR middle-end/51071 @@ -12,7 +17,7 @@ PR c++/53322 * g++.dg/warn/Wunused-local-typedefs.C: Adjust to use -Wunused - instead of -Wunused-local-typedefs. + instead of -Wunused-local-typedefs. 2012-05-21 Paolo Carlini 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 0000000..2a0e5be --- /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 -- 2.7.4