diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gfortran.dg/alloc_comp_transformational_1.f90 | |
download | cbb-gcc-4.6.4-upstream.tar.bz2 cbb-gcc-4.6.4-upstream.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gfortran.dg/alloc_comp_transformational_1.f90')
-rw-r--r-- | gcc/testsuite/gfortran.dg/alloc_comp_transformational_1.f90 | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_transformational_1.f90 b/gcc/testsuite/gfortran.dg/alloc_comp_transformational_1.f90 new file mode 100644 index 000000000..13ee8a88b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/alloc_comp_transformational_1.f90 @@ -0,0 +1,80 @@ +! { dg-do run } +! Tests the fix for PR41478, in which double frees would occur because +! transformational intrinsics did not copy the allocatable components +! so that they were (sometimes) freed twice on exit. In addition, +! The original allocatable components of a1 were not freed, so that +! memory leakage occurred. +! +! Contributed by Juergen Reuter <reuter@physik.uni-freiburg.de> +! + type :: container_t + integer, dimension(:), allocatable :: entry + integer index + end type container_t + call foo + call bar +contains +! +! This is the reported problem. +! + subroutine foo + type(container_t), dimension(4) :: a1, a2, a3 + integer :: i + do i = 1, 4 + allocate (a1(i)%entry (2), a2(i)%entry (2), a3(i)%entry (2)) + a1(i)%entry = [1,2] + a2(i)%entry = [3,4] + a3(i)%entry = [4,5] + a1(i)%index = i + a2(i)%index = i + a3(i)%index = i + end do + a1(1:2) = pack (a2, [.true., .false., .true., .false.]) + do i = 1, 4 + if (.not.allocated (a1(i)%entry)) call abort + if (i .gt. 2) then + if (any (a1(i)%entry .ne. [1,2])) call abort + else + if (any (a1(i)%entry .ne. [3,4])) call abort + end if + end do +! +! Now check unpack +! + a1 = unpack (a1, [.true., .true., .false., .false.], a3) + if (any (a1%index .ne. [1,3,3,4])) call abort + do i = 1, 4 + if (.not.allocated (a1(i)%entry)) call abort + if (i .gt. 2) then + if (any (a1(i)%entry .ne. [4,5])) call abort + else + if (any (a1(i)%entry .ne. [3,4])) call abort + end if + end do + end subroutine +! +! Other all transformational intrinsics display it. Having done +! PACK and UNPACK, just use TRANSPOSE as a demonstrator. +! + subroutine bar + type(container_t), dimension(2,2) :: a1, a2 + integer :: i, j + do i = 1, 2 + do j = 1, 2 + allocate (a1(i, j)%entry (2), a2(i, j)%entry (2)) + a1(i, j)%entry = [i,j] + a2(i, j)%entry = [i,j] + a1(i,j)%index = j + (i - 1)*2 + a2(i,j)%index = j + (i - 1)*2 + end do + end do + a1 = transpose (a2) + do i = 1, 2 + do j = 1, 2 + if (a1(i,j)%index .ne. i + (j - 1)*2) call abort + if (any (a1(i,j)%entry .ne. [j,i])) call abort + end do + end do + end subroutine +end + |