aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gfortran.dg/alloc_comp_transformational_1.f90
diff options
context:
space:
mode:
authorBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
committerBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
commit1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch)
treec607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/gcc/testsuite/gfortran.dg/alloc_comp_transformational_1.f90
parent283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff)
downloadtoolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/gcc/testsuite/gfortran.dg/alloc_comp_transformational_1.f90')
-rw-r--r--gcc-4.9/gcc/testsuite/gfortran.dg/alloc_comp_transformational_1.f9080
1 files changed, 80 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/gfortran.dg/alloc_comp_transformational_1.f90 b/gcc-4.9/gcc/testsuite/gfortran.dg/alloc_comp_transformational_1.f90
new file mode 100644
index 000000000..13ee8a88b
--- /dev/null
+++ b/gcc-4.9/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
+