From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; 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. --- .../gfortran.dg/alloc_comp_constructor_1.f90 | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/alloc_comp_constructor_1.f90 (limited to 'gcc/testsuite/gfortran.dg/alloc_comp_constructor_1.f90') diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_constructor_1.f90 b/gcc/testsuite/gfortran.dg/alloc_comp_constructor_1.f90 new file mode 100644 index 000000000..969e70309 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/alloc_comp_constructor_1.f90 @@ -0,0 +1,108 @@ +! { dg-do run } +! { dg-options "-fdump-tree-original" } +! Test constructors of derived type with allocatable components (PR 20541). +! +! Contributed by Erik Edelmann +! and Paul Thomas +! + +Program test_constructor + + implicit none + + type :: thytype + integer(4) :: a(2,2) + end type thytype + + type :: mytype + integer(4), allocatable :: a(:, :) + type(thytype), allocatable :: q(:) + end type mytype + + type (mytype) :: x + type (thytype) :: foo = thytype(reshape ([43, 100, 54, 76], [2,2])) + integer :: y(0:1, -1:0) = reshape ([42, 99, 55, 77], [2,2]) + integer, allocatable :: yy(:,:) + type (thytype), allocatable :: bar(:) + integer :: i + + ! Check that null() works + x = mytype(null(), null()) + if (allocated(x%a) .or. allocated(x%q)) call abort() + + ! Check that unallocated allocatables work + x = mytype(yy, bar) + if (allocated(x%a) .or. allocated(x%q)) call abort() + + ! Check that non-allocatables work + x = mytype(y, [foo, foo]) + if (.not.allocated(x%a) .or. .not.allocated(x%q)) call abort() + if (any(lbound(x%a) /= lbound(y))) call abort() + if (any(ubound(x%a) /= ubound(y))) call abort() + if (any(x%a /= y)) call abort() + if (size(x%q) /= 2) call abort() + do i = 1, 2 + if (any(x%q(i)%a /= foo%a)) call abort() + end do + + ! Check that allocated allocatables work + allocate(yy(size(y,1), size(y,2))) + yy = y + allocate(bar(2)) + bar = [foo, foo] + x = mytype(yy, bar) + if (.not.allocated(x%a) .or. .not.allocated(x%q)) call abort() + if (any(x%a /= y)) call abort() + if (size(x%q) /= 2) call abort() + do i = 1, 2 + if (any(x%q(i)%a /= foo%a)) call abort() + end do + + ! Functions returning arrays + x = mytype(bluhu(), null()) + if (.not.allocated(x%a) .or. allocated(x%q)) call abort() + if (any(x%a /= reshape ([41, 98, 54, 76], [2,2]))) call abort() + + ! Functions returning allocatable arrays + x = mytype(blaha(), null()) + if (.not.allocated(x%a) .or. allocated(x%q)) call abort() + if (any(x%a /= reshape ([40, 97, 53, 75], [2,2]))) call abort() + + ! Check that passing the constructor to a procedure works + call check_mytype (mytype(y, [foo, foo])) + +contains + + subroutine check_mytype(x) + type(mytype), intent(in) :: x + integer :: i + + if (.not.allocated(x%a) .or. .not.allocated(x%q)) call abort() + if (any(lbound(x%a) /= lbound(y))) call abort() + if (any(ubound(x%a) /= ubound(y))) call abort() + if (any(x%a /= y)) call abort() + if (size(x%q) /= 2) call abort() + do i = 1, 2 + if (any(x%q(i)%a /= foo%a)) call abort() + end do + + end subroutine check_mytype + + + function bluhu() + integer :: bluhu(2,2) + + bluhu = reshape ([41, 98, 54, 76], [2,2]) + end function bluhu + + + function blaha() + integer, allocatable :: blaha(:,:) + + allocate(blaha(2,2)) + blaha = reshape ([40, 97, 53, 75], [2,2]) + end function blaha + +end program test_constructor +! { dg-final { scan-tree-dump-times "builtin_free" 19 "original" } } +! { dg-final { cleanup-tree-dump "original" } } -- cgit v1.2.3