File: alloc_comp_deep_copy_1.f03

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (270 lines) | stat: -rw-r--r-- 7,944 bytes parent folder | download | duplicates (3)
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
! { dg-do run }
!
! Check fix for correctly deep copying allocatable components.
! PR fortran/59678
! Contributed by Andre Vehreschild  <vehre@gmx.de>
!
program alloc_comp_copy_test

  type InnerT
    integer :: ii
    integer, allocatable :: ai
    integer, allocatable :: v(:)
  end type InnerT

  type T
    integer :: i
    integer, allocatable :: a_i
    type(InnerT), allocatable :: it
    type(InnerT), allocatable :: vec(:)
  end type T

  type(T) :: o1, o2
  class(T), allocatable :: o3, o4
  o1%i = 42

  call copyO(o1, o2)
  if (o2%i /= 42) STOP 1
  if (allocated(o2%a_i)) STOP 2
  if (allocated(o2%it)) STOP 3
  if (allocated(o2%vec)) STOP 4

  allocate (o1%a_i, source=2)
  call copyO(o1, o2)
  if (o2%i /= 42) STOP 5
  if (.not. allocated(o2%a_i)) STOP 6
  if (o2%a_i /= 2) STOP 7
  if (allocated(o2%it)) STOP 8
  if (allocated(o2%vec)) STOP 9

  allocate (o1%it)
  o1%it%ii = 3
  call copyO(o1, o2)
  if (o2%i /= 42) STOP 10
  if (.not. allocated(o2%a_i)) STOP 11
  if (o2%a_i /= 2) STOP 12
  if (.not. allocated(o2%it)) STOP 13
  if (o2%it%ii /= 3) STOP 14
  if (allocated(o2%it%ai)) STOP 15
  if (allocated(o2%it%v)) STOP 16
  if (allocated(o2%vec)) STOP 17

  allocate (o1%it%ai)
  o1%it%ai = 4
  call copyO(o1, o2)
  if (o2%i /= 42) STOP 18
  if (.not. allocated(o2%a_i)) STOP 19
  if (o2%a_i /= 2) STOP 20
  if (.not. allocated(o2%it)) STOP 21
  if (o2%it%ii /= 3) STOP 22
  if (.not. allocated(o2%it%ai)) STOP 23
  if (o2%it%ai /= 4) STOP 24
  if (allocated(o2%it%v)) STOP 25
  if (allocated(o2%vec)) STOP 26

  allocate (o1%it%v(3), source= 5)
  call copyO(o1, o2)
  if (o2%i /= 42) STOP 27
  if (.not. allocated(o2%a_i)) STOP 28
  if (o2%a_i /= 2) STOP 29
  if (.not. allocated(o2%it)) STOP 30
  if (o2%it%ii /= 3) STOP 31
  if (.not. allocated(o2%it%ai)) STOP 32
  if (o2%it%ai /= 4) STOP 33
  if (.not. allocated(o2%it%v)) STOP 34
  if (any (o2%it%v /= 5) .or. size (o2%it%v) /= 3) STOP 35
  if (allocated(o2%vec)) STOP 36

  allocate (o1%vec(2))
  o1%vec(:)%ii = 6
  call copyO(o1, o2)
  if (o2%i /= 42) STOP 37
  if (.not. allocated(o2%a_i)) STOP 38
  if (o2%a_i /= 2) STOP 39
  if (.not. allocated(o2%it)) STOP 40
  if (o2%it%ii /= 3) STOP 41
  if (.not. allocated(o2%it%ai)) STOP 42
  if (o2%it%ai /= 4) STOP 43
  if (.not. allocated(o2%it%v)) STOP 44
  if (size (o2%it%v) /= 3) STOP 45
  if (any (o2%it%v /= 5)) STOP 46
  if (.not. allocated(o2%vec)) STOP 47
  if (size(o2%vec) /= 2) STOP 48
  if (any(o2%vec(:)%ii /= 6)) STOP 49
  if (allocated(o2%vec(1)%ai) .or. allocated(o2%vec(2)%ai)) STOP 50
  if (allocated(o2%vec(1)%v) .or. allocated(o2%vec(2)%v)) STOP 51

  allocate (o1%vec(2)%ai)
  o1%vec(2)%ai = 7
  call copyO(o1, o2)
  if (o2%i /= 42) STOP 52
  if (.not. allocated(o2%a_i)) STOP 53
  if (o2%a_i /= 2) STOP 54
  if (.not. allocated(o2%it)) STOP 55
  if (o2%it%ii /= 3) STOP 56
  if (.not. allocated(o2%it%ai)) STOP 57
  if (o2%it%ai /= 4) STOP 58
  if (.not. allocated(o2%it%v)) STOP 59
  if (size (o2%it%v) /= 3) STOP 60
  if (any (o2%it%v /= 5)) STOP 61
  if (.not. allocated(o2%vec)) STOP 62
  if (size(o2%vec) /= 2) STOP 63
  if (any(o2%vec(:)%ii /= 6)) STOP 64
  if (allocated(o2%vec(1)%ai)) STOP 65
  if (.not. allocated(o2%vec(2)%ai)) STOP 66
  if (o2%vec(2)%ai /= 7) STOP 67
  if (allocated(o2%vec(1)%v) .or. allocated(o2%vec(2)%v)) STOP 68

  allocate (o1%vec(1)%v(3))
  o1%vec(1)%v = [8, 9, 10]
  call copyO(o1, o2)
  if (o2%i /= 42) STOP 69
  if (.not. allocated(o2%a_i)) STOP 70
  if (o2%a_i /= 2) STOP 71
  if (.not. allocated(o2%it)) STOP 72
  if (o2%it%ii /= 3) STOP 73
  if (.not. allocated(o2%it%ai)) STOP 74
  if (o2%it%ai /= 4) STOP 75
  if (.not. allocated(o2%it%v)) STOP 76
  if (size (o2%it%v) /= 3) STOP 77
  if (any (o2%it%v /= 5)) STOP 78
  if (.not. allocated(o2%vec)) STOP 79
  if (size(o2%vec) /= 2) STOP 80
  if (any(o2%vec(:)%ii /= 6)) STOP 81
  if (allocated(o2%vec(1)%ai)) STOP 82
  if (.not. allocated(o2%vec(2)%ai)) STOP 83
  if (o2%vec(2)%ai /= 7) STOP 84
  if (.not. allocated(o2%vec(1)%v)) STOP 85
  if (any (o2%vec(1)%v /= [8,9,10])) STOP 86
  if (allocated(o2%vec(2)%v)) STOP 87

  ! Now all the above for class objects.
  allocate (o3, o4)
  o3%i = 42

  call copyO(o3, o4)
  if (o4%i /= 42) STOP 88
  if (allocated(o4%a_i)) STOP 89
  if (allocated(o4%it)) STOP 90
  if (allocated(o4%vec)) STOP 91

  allocate (o3%a_i, source=2)
  call copyO(o3, o4)
  if (o4%i /= 42) STOP 92
  if (.not. allocated(o4%a_i)) STOP 93
  if (o4%a_i /= 2) STOP 94
  if (allocated(o4%it)) STOP 95
  if (allocated(o4%vec)) STOP 96

  allocate (o3%it)
  o3%it%ii = 3
  call copyO(o3, o4)
  if (o4%i /= 42) STOP 97
  if (.not. allocated(o4%a_i)) STOP 98
  if (o4%a_i /= 2) STOP 99
  if (.not. allocated(o4%it)) STOP 100
  if (o4%it%ii /= 3) STOP 101
  if (allocated(o4%it%ai)) STOP 102
  if (allocated(o4%it%v)) STOP 103
  if (allocated(o4%vec)) STOP 104

  allocate (o3%it%ai)
  o3%it%ai = 4
  call copyO(o3, o4)
  if (o4%i /= 42) STOP 105
  if (.not. allocated(o4%a_i)) STOP 106
  if (o4%a_i /= 2) STOP 107
  if (.not. allocated(o4%it)) STOP 108
  if (o4%it%ii /= 3) STOP 109
  if (.not. allocated(o4%it%ai)) STOP 110
  if (o4%it%ai /= 4) STOP 111
  if (allocated(o4%it%v)) STOP 112
  if (allocated(o4%vec)) STOP 113

  allocate (o3%it%v(3), source= 5)
  call copyO(o3, o4)
  if (o4%i /= 42) STOP 114
  if (.not. allocated(o4%a_i)) STOP 115
  if (o4%a_i /= 2) STOP 116
  if (.not. allocated(o4%it)) STOP 117
  if (o4%it%ii /= 3) STOP 118
  if (.not. allocated(o4%it%ai)) STOP 119
  if (o4%it%ai /= 4) STOP 120
  if (.not. allocated(o4%it%v)) STOP 121
  if (any (o4%it%v /= 5) .or. size (o4%it%v) /= 3) STOP 122
  if (allocated(o4%vec)) STOP 123

  allocate (o3%vec(2))
  o3%vec(:)%ii = 6
  call copyO(o3, o4)
  if (o4%i /= 42) STOP 124
  if (.not. allocated(o4%a_i)) STOP 125
  if (o4%a_i /= 2) STOP 126
  if (.not. allocated(o4%it)) STOP 127
  if (o4%it%ii /= 3) STOP 128
  if (.not. allocated(o4%it%ai)) STOP 129
  if (o4%it%ai /= 4) STOP 130
  if (.not. allocated(o4%it%v)) STOP 131
  if (size (o4%it%v) /= 3) STOP 132
  if (any (o4%it%v /= 5)) STOP 133
  if (.not. allocated(o4%vec)) STOP 134
  if (size(o4%vec) /= 2) STOP 135
  if (any(o4%vec(:)%ii /= 6)) STOP 136
  if (allocated(o4%vec(1)%ai) .or. allocated(o4%vec(2)%ai)) STOP 137
  if (allocated(o4%vec(1)%v) .or. allocated(o4%vec(2)%v)) STOP 138

  allocate (o3%vec(2)%ai)
  o3%vec(2)%ai = 7
  call copyO(o3, o4)
  if (o4%i /= 42) STOP 139
  if (.not. allocated(o4%a_i)) STOP 140
  if (o4%a_i /= 2) STOP 141
  if (.not. allocated(o4%it)) STOP 142
  if (o4%it%ii /= 3) STOP 143
  if (.not. allocated(o4%it%ai)) STOP 144
  if (o4%it%ai /= 4) STOP 145
  if (.not. allocated(o4%it%v)) STOP 146
  if (size (o4%it%v) /= 3) STOP 147
  if (any (o4%it%v /= 5)) STOP 148
  if (.not. allocated(o4%vec)) STOP 149
  if (size(o4%vec) /= 2) STOP 150
  if (any(o4%vec(:)%ii /= 6)) STOP 151
  if (allocated(o4%vec(1)%ai)) STOP 152
  if (.not. allocated(o4%vec(2)%ai)) STOP 153
  if (o4%vec(2)%ai /= 7) STOP 154
  if (allocated(o4%vec(1)%v) .or. allocated(o4%vec(2)%v)) STOP 155

  allocate (o3%vec(1)%v(3))
  o3%vec(1)%v = [8, 9, 10]
  call copyO(o3, o4)
  if (o4%i /= 42) STOP 156
  if (.not. allocated(o4%a_i)) STOP 157
  if (o4%a_i /= 2) STOP 158
  if (.not. allocated(o4%it)) STOP 159
  if (o4%it%ii /= 3) STOP 160
  if (.not. allocated(o4%it%ai)) STOP 161
  if (o4%it%ai /= 4) STOP 162
  if (.not. allocated(o4%it%v)) STOP 163
  if (size (o4%it%v) /= 3) STOP 164
  if (any (o4%it%v /= 5)) STOP 165
  if (.not. allocated(o4%vec)) STOP 166
  if (size(o4%vec) /= 2) STOP 167
  if (any(o4%vec(:)%ii /= 6)) STOP 168
  if (allocated(o4%vec(1)%ai)) STOP 169
  if (.not. allocated(o4%vec(2)%ai)) STOP 170
  if (o4%vec(2)%ai /= 7) STOP 171
  if (.not. allocated(o4%vec(1)%v)) STOP 172
  if (any (o4%vec(1)%v /= [8,9,10])) STOP 173
  if (allocated(o4%vec(2)%v)) STOP 174

contains

  subroutine copyO(src, dst)
    type(T), intent(in) :: src
    type(T), intent(out) :: dst

    dst = src
  end subroutine copyO

end program alloc_comp_copy_test