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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
! { dg-do run }
! { dg-options "-fcoarray=single" }
!
! PR fortran/50981
! PR fortran/54618
!
implicit none
type t
integer, allocatable :: i
end type t
type, extends (t):: t2
integer, allocatable :: j
end type t2
class(t), allocatable :: xa, xa2(:), xac[:], xa2c(:)[:]
class(t), pointer :: xp, xp2(:)
xp => null()
xp2 => null()
call suba(alloc=.false., prsnt=.false.)
call suba(xa, alloc=.false., prsnt=.true.)
if (.not. allocated (xa)) call abort ()
if (.not. allocated (xa%i)) call abort ()
if (xa%i /= 5) call abort ()
xa%i = -3
call suba(xa, alloc=.true., prsnt=.true.)
if (allocated (xa)) call abort ()
call suba2(alloc=.false., prsnt=.false.)
call suba2(xa2, alloc=.false., prsnt=.true.)
if (.not. allocated (xa2)) call abort ()
if (size (xa2) /= 1) call abort ()
if (.not. allocated (xa2(1)%i)) call abort ()
if (xa2(1)%i /= 5) call abort ()
xa2(1)%i = -3
call suba2(xa2, alloc=.true., prsnt=.true.)
if (allocated (xa2)) call abort ()
call subp(alloc=.false., prsnt=.false.)
call subp(xp, alloc=.false., prsnt=.true.)
if (.not. associated (xp)) call abort ()
if (.not. allocated (xp%i)) call abort ()
if (xp%i /= 5) call abort ()
xp%i = -3
call subp(xp, alloc=.true., prsnt=.true.)
if (associated (xp)) call abort ()
call subp2(alloc=.false., prsnt=.false.)
call subp2(xp2, alloc=.false., prsnt=.true.)
if (.not. associated (xp2)) call abort ()
if (size (xp2) /= 1) call abort ()
if (.not. allocated (xp2(1)%i)) call abort ()
if (xp2(1)%i /= 5) call abort ()
xp2(1)%i = -3
call subp2(xp2, alloc=.true., prsnt=.true.)
if (associated (xp2)) call abort ()
call subac(alloc=.false., prsnt=.false.)
call subac(xac, alloc=.false., prsnt=.true.)
if (.not. allocated (xac)) call abort ()
if (.not. allocated (xac%i)) call abort ()
if (xac%i /= 5) call abort ()
xac%i = -3
call subac(xac, alloc=.true., prsnt=.true.)
if (allocated (xac)) call abort ()
call suba2c(alloc=.false., prsnt=.false.)
call suba2c(xa2c, alloc=.false., prsnt=.true.)
if (.not. allocated (xa2c)) call abort ()
if (size (xa2c) /= 1) call abort ()
if (.not. allocated (xa2c(1)%i)) call abort ()
if (xa2c(1)%i /= 5) call abort ()
xa2c(1)%i = -3
call suba2c(xa2c, alloc=.true., prsnt=.true.)
if (allocated (xa2c)) call abort ()
contains
subroutine suba2c(x, prsnt, alloc)
class(t), optional, allocatable :: x(:)[:]
logical prsnt, alloc
if (present (x) .neqv. prsnt) call abort ()
if (prsnt) then
if (alloc .neqv. allocated(x)) call abort ()
if (.not. allocated (x)) then
allocate (x(1)[*])
x(1)%i = 5
else
if (x(1)%i /= -3) call abort()
deallocate (x)
end if
end if
end subroutine suba2c
subroutine subac(x, prsnt, alloc)
class(t), optional, allocatable :: x[:]
logical prsnt, alloc
if (present (x) .neqv. prsnt) call abort ()
if (present (x)) then
if (alloc .neqv. allocated(x)) call abort ()
if (.not. allocated (x)) then
allocate (x[*])
x%i = 5
else
if (x%i /= -3) call abort()
deallocate (x)
end if
end if
end subroutine subac
subroutine suba2(x, prsnt, alloc)
class(t), optional, allocatable :: x(:)
logical prsnt, alloc
if (present (x) .neqv. prsnt) call abort ()
if (prsnt) then
if (alloc .neqv. allocated(x)) call abort ()
if (.not. allocated (x)) then
allocate (x(1))
x(1)%i = 5
else
if (x(1)%i /= -3) call abort()
deallocate (x)
end if
end if
end subroutine suba2
subroutine suba(x, prsnt, alloc)
class(t), optional, allocatable :: x
logical prsnt, alloc
if (present (x) .neqv. prsnt) call abort ()
if (present (x)) then
if (alloc .neqv. allocated(x)) call abort ()
if (.not. allocated (x)) then
allocate (x)
x%i = 5
else
if (x%i /= -3) call abort()
deallocate (x)
end if
end if
end subroutine suba
subroutine subp2(x, prsnt, alloc)
class(t), optional, pointer :: x(:)
logical prsnt, alloc
if (present (x) .neqv. prsnt) call abort ()
if (present (x)) then
if (alloc .neqv. associated(x)) call abort ()
if (.not. associated (x)) then
allocate (x(1))
x(1)%i = 5
else
if (x(1)%i /= -3) call abort()
deallocate (x)
end if
end if
end subroutine subp2
subroutine subp(x, prsnt, alloc)
class(t), optional, pointer :: x
logical prsnt, alloc
if (present (x) .neqv. prsnt) call abort ()
if (present (x)) then
if (alloc .neqv. associated(x)) call abort ()
if (.not. associated (x)) then
allocate (x)
x%i = 5
else
if (x%i /= -3) call abort()
deallocate (x)
end if
end if
end subroutine subp
end
|