URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gfortran.dg/] [alloc_comp_basics_1.f90] - Rev 700
Go to most recent revision | Compare with Previous | Blame | View Log
! { dg-do run }! { dg-options "-fdump-tree-original" }!! Check some basic functionality of allocatable components, including that they! are nullified when created and automatically deallocated when! 1. A variable goes out of scope! 2. INTENT(OUT) dummies! 3. Function results!!! Contributed by Erik Edelmann <eedelmann@gcc.gnu.org>! and Paul Thomas <pault@gcc.gnu.org>!module alloc_mimplicit nonetype :: alloc1real, allocatable :: x(:)end type alloc1end module alloc_mprogram allocuse alloc_mimplicit nonetype :: alloc2type(alloc1), allocatable :: a1(:)integer, allocatable :: a2(:)end type alloc2type(alloc2) :: binteger :: itype(alloc2), allocatable :: c(:)if (allocated(b%a2) .OR. allocated(b%a1)) thenwrite (0, *) 'main - 1'call abort()end if! 3 calls to _gfortran_deallocate (INTENT(OUT) dummy)call allocate_alloc2(b)call check_alloc2(b)do i = 1, size(b%a1)! 1 call to _gfortran_deallocatedeallocate(b%a1(i)%x)end do! 3 calls to _gfortran_deallocate (INTENT(OUT) dummy)call allocate_alloc2(b)call check_alloc2(return_alloc2())! 3 calls to _gfortran_deallocate (function result)allocate(c(1))! 3 calls to _gfortran_deallocate (INTENT(OUT) dummy)call allocate_alloc2(c(1))! 4 calls to _gfortran_deallocatedeallocate(c)! 7 calls to _gfortran_deallocate (b (3) and c(4) goes aout of scope)containssubroutine allocate_alloc2(b)type(alloc2), intent(out) :: binteger :: iif (allocated(b%a2) .OR. allocated(b%a1)) thenwrite (0, *) 'allocate_alloc2 - 1'call abort()end ifallocate (b%a2(3))b%a2 = [ 1, 2, 3 ]allocate (b%a1(3))do i = 1, 3if (allocated(b%a1(i)%x)) thenwrite (0, *) 'allocate_alloc2 - 2', icall abort()end ifallocate (b%a1(i)%x(3))b%a1(i)%x = i + [ 1.0, 2.0, 3.0 ]end doend subroutine allocate_alloc2type(alloc2) function return_alloc2() result(b)if (allocated(b%a2) .OR. allocated(b%a1)) thenwrite (0, *) 'return_alloc2 - 1'call abort()end ifallocate (b%a2(3))b%a2 = [ 1, 2, 3 ]allocate (b%a1(3))do i = 1, 3if (allocated(b%a1(i)%x)) thenwrite (0, *) 'return_alloc2 - 2', icall abort()end ifallocate (b%a1(i)%x(3))b%a1(i)%x = i + [ 1.0, 2.0, 3.0 ]end doend function return_alloc2subroutine check_alloc2(b)type(alloc2), intent(in) :: bif (.NOT.(allocated(b%a2) .AND. allocated(b%a1))) thenwrite (0, *) 'check_alloc2 - 1'call abort()end ifif (any(b%a2 /= [ 1, 2, 3 ])) thenwrite (0, *) 'check_alloc2 - 2'call abort()end ifdo i = 1, 3if (.NOT.allocated(b%a1(i)%x)) thenwrite (0, *) 'check_alloc2 - 3', icall abort()end ifif (any(b%a1(i)%x /= i + [ 1.0, 2.0, 3.0 ])) thenwrite (0, *) 'check_alloc2 - 4', icall abort()end ifend doend subroutine check_alloc2end program alloc! { dg-final { scan-tree-dump-times "builtin_free" 18 "original" } }! { dg-final { cleanup-tree-dump "original" } }! { dg-final { cleanup-modules "alloc_m" } }
Go to most recent revision | Compare with Previous | Blame | View Log
