aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gfortran.dg/class_array_16.f90
blob: fc8edbf140a0a3fdc91826f9a876152113dd082f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
! { dg-do run }
! { dg-options "-fdump-tree-original" }
!
module m
  implicit none
  type t
  end type t

  type, extends(t) :: t2
  end type t2

  type(t) :: var_t
  type(t2) :: var_t2
contains
  subroutine sub(x)
     class(t), allocatable, intent(out) :: x(:)

     if (allocated (x)) call abort()
     if (.not. same_type_as(x, var_t)) call abort()

     allocate (t2 :: x(5))
  end subroutine sub

  subroutine sub2(x)
     class(t), allocatable, OPTIONAL, intent(out) :: x(:)

     if (.not. present(x)) return
     if (allocated (x)) call abort()
     if (.not. same_type_as(x, var_t)) call abort()

     allocate (t2 :: x(5))
  end subroutine sub2
end module m

use m
implicit none
class(t), save, allocatable :: y(:)

if (allocated (y)) call abort()
if (.not. same_type_as(y,var_t)) call abort()

call sub(y)
if (.not.allocated(y)) call abort()
if (.not. same_type_as(y, var_t2)) call abort()
if (size (y) /= 5) call abort()

call sub(y)
if (.not.allocated(y)) call abort()
if (.not. same_type_as(y, var_t2)) call abort()
if (size (y) /= 5) call abort()

deallocate (y)
if (allocated (y)) call abort()
if (.not. same_type_as(y,var_t)) call abort()

call sub2()

call sub2(y)
if (.not.allocated(y)) call abort()
if (.not. same_type_as(y, var_t2)) call abort()
if (size (y) /= 5) call abort()

call sub2(y)
if (.not.allocated(y)) call abort()
if (.not. same_type_as(y, var_t2)) call abort()
if (size (y) /= 5) call abort()
end

! { dg-final { scan-tree-dump-times "__builtin_free" 5 "original" } }
! { dg-final { scan-tree-dump-times "finally" 0 "original" } }
! { dg-final { cleanup-tree-dump "original" } }