URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gfortran.dg/] [alloc_comp_constructor_1.f90] - Rev 694
Compare with Previous | Blame | View Log
! { dg-do run }! { dg-options "-fdump-tree-original" }! Test constructors of derived type with allocatable components (PR 20541).!! Contributed by Erik Edelmann <eedelmann@gcc.gnu.org>! and Paul Thomas <pault@gcc.gnu.org>!Program test_constructorimplicit nonetype :: thytypeinteger(4) :: a(2,2)end type thytypetype :: mytypeinteger(4), allocatable :: a(:, :)type(thytype), allocatable :: q(:)end type mytypetype (mytype) :: xtype (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() worksx = mytype(null(), null())if (allocated(x%a) .or. allocated(x%q)) call abort()! Check that unallocated allocatables workx = mytype(yy, bar)if (allocated(x%a) .or. allocated(x%q)) call abort()! Check that non-allocatables workx = 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, 2if (any(x%q(i)%a /= foo%a)) call abort()end do! Check that allocated allocatables workallocate(yy(size(y,1), size(y,2)))yy = yallocate(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, 2if (any(x%q(i)%a /= foo%a)) call abort()end do! Functions returning arraysx = 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 arraysx = 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 workscall check_mytype (mytype(y, [foo, foo]))containssubroutine check_mytype(x)type(mytype), intent(in) :: xinteger :: iif (.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, 2if (any(x%q(i)%a /= foo%a)) call abort()end doend subroutine check_mytypefunction bluhu()integer :: bluhu(2,2)bluhu = reshape ([41, 98, 54, 76], [2,2])end function bluhufunction blaha()integer, allocatable :: blaha(:,:)allocate(blaha(2,2))blaha = reshape ([40, 97, 53, 75], [2,2])end function blahaend program test_constructor! { dg-final { scan-tree-dump-times "builtin_free" 19 "original" } }! { dg-final { cleanup-tree-dump "original" } }
