OSDN Git Service

2012-05-23 Tobias Burnus <burnus@net-b.de>
authorburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 23 May 2012 19:08:52 +0000 (19:08 +0000)
committerburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 23 May 2012 19:08:52 +0000 (19:08 +0000)
        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: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@187808 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/realloc_on_assign_15.f90 [new file with mode: 0644]

index f061f46..367383e 100644 (file)
@@ -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-07  Tobias Burnus  <burnus@net-b.de>
 
        Backport from mainline:
index bbe5afe..d28c56d 100644 (file)
@@ -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,
index 3c680d2..b54a354 100644 (file)
@@ -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>
 
        PR tree-optimization/53408
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 (file)
index 0000000..2a0e5be
--- /dev/null
@@ -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