summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/realloc_on_assign_15.f90
blob: 2a0e5be91011da4f6d80ab5ebb342d5c3d083d32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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