Debian Codegraph @

libgomp/testsuite/libgomp.fortran/map-alloc-comp-9.f90

raw
1 ! { dg-additional-options "-cpp" }
2 !
3 ! Ensure that polymorphic mapping is diagnosed as undefined behavior
4 ! Ensure that static access to polymorphic variables works
5
6 ! Some extended tests are only run with shared memory
7 ! To enforce this (where possible) on the device side:
8 ! #define USE_USM_REQUIREMENT
9 ! which is done in map-alloc-comp-9-usm.f90
10
11 subroutine test(case)
12 implicit none(type, external)
13 #ifdef USE_USM_REQUIREMENT
14 !$omp requires unified_shared_memory
15 #endif
16
17 type t
18 integer :: x(4)
19 end type t
20
21 type ta
22 integer, allocatable :: x(:)
23 end type ta
24
25 type t2
26 class(t), allocatable :: x
27 class(t), allocatable :: x2(:)
28 end type t2
29
30 type t3
31 type(t2) :: y
32 type(t2) :: y2(2)
33 end type t3
34
35 type t4
36 type(t3), allocatable :: y
37 type(t3), allocatable :: y2(:)
38 end type t4
39
40 integer, value :: case
41
42 logical :: is_shared_mem
43
44 ! Mangle stack addresses
45 integer, volatile :: case_var(100*case)
46
47 type(t), allocatable :: var1
48 type(ta), allocatable :: var1a
49 class(t), allocatable :: var2
50 type(t2), allocatable :: var3
51 type(t4), allocatable :: var4
52
53 case_var(100) = 0
54 !print *, 'case', case
55
56 var1 = t([1,2,3,4])
57 var1a = ta([-1,-2,-3,-4,-5])
58
59 var2 = t([11,22,33,44])
60
61 allocate(t2 :: var3)
62 allocate(t :: var3%x)
63 allocate(t :: var3%x2(2))
64 var3%x%x = [111,222,333,444]
65 var3%x2(1)%x = 2*[111,222,333,444]
66 var3%x2(2)%x = 3*[111,222,333,444]
67
68 allocate(t4 :: var4)
69 allocate(t3 :: var4%y)
70 allocate(t3 :: var4%y2(2))
71 allocate(t :: var4%y%y%x)
72 allocate(t :: var4%y%y%x2(2))
73 allocate(t :: var4%y2(1)%y%x)
74 allocate(t :: var4%y2(1)%y%x2(2))
75 allocate(t :: var4%y2(2)%y%x)
76 allocate(t :: var4%y2(2)%y%x2(2))
77 var4%y%y%x%x = -1 * [1111,2222,3333,4444]
78 var4%y%y%x2(1)%x = -2 * [1111,2222,3333,4444]
79 var4%y%y%x2(2)%x = -3 * [1111,2222,3333,4444]
80 var4%y2(1)%y%x%x = -4 * [1111,2222,3333,4444]
81 var4%y2(1)%y%x2(1)%x = -5 * [1111,2222,3333,4444]
82 var4%y2(1)%y%x2(2)%x = -6 * [1111,2222,3333,4444]
83 var4%y2(2)%y%x%x = -7 * [1111,2222,3333,4444]
84 var4%y2(2)%y%x2(1)%x = -8 * [1111,2222,3333,4444]
85 var4%y2(2)%y%x2(2)%x = -9 * [1111,2222,3333,4444]
86
87 #ifdef USE_USM_REQUIREMENT
88 is_shared_mem = .true.
89 #else
90 is_shared_mem = .false.
91 !$omp target map(to: is_shared_mem)
92 is_shared_mem = .true.
93 !$omp end target
94 #endif
95
96 if (case == 1) then
97 ! implicit mapping
98 !$omp target
99 if (any (var1%x /= [1,2,3,4])) stop 1
100 var1%x = 2 * var1%x
101 !$omp end target
102
103 !$omp target
104 if (any (var1a%x /= [-1,-2,-3,-4])) stop 2
105 var1a%x = 3 * var1a%x
106 !$omp end target
107
108 !$omp target ! { dg-warning "Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
109 if (any (var2%x /= [11,22,33,44])) stop 3
110 var2%x = 4 * var2%x
111 !$omp end target
112
113 !$omp target ! { dg-warning "Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
114 if (any (var3%x%x /= [111,222,333,444])) stop 4
115 var3%x%x = 5 * var3%x%x
116 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
117 if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 4
118 if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 4
119 var3%x2(1)%x = 5 * var3%x2(1)%x
120 var3%x2(2)%x = 5 * var3%x2(2)%x
121 end if
122 !$omp end target
123
124 !$omp target ! { dg-warning "Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
125 if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 5
126 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
127 if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 5
128 if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 5
129 endif
130 if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 5
131 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
132 if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 5
133 if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 5
134 endif
135 if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 5
136 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
137 if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 5
138 if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 5
139 end if
140 var4%y%y%x%x = 6 * var4%y%y%x%x
141 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
142 var4%y%y%x2(1)%x = 6 * var4%y%y%x2(1)%x
143 var4%y%y%x2(2)%x = 6 * var4%y%y%x2(2)%x
144 endif
145 var4%y2(1)%y%x%x = 6 * var4%y2(1)%y%x%x
146 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
147 var4%y2(1)%y%x2(1)%x = 6 * var4%y2(1)%y%x2(1)%x
148 var4%y2(1)%y%x2(2)%x = 6 * var4%y2(1)%y%x2(2)%x
149 endif
150 var4%y2(2)%y%x%x = 6 * var4%y2(2)%y%x%x
151 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
152 var4%y2(2)%y%x2(1)%x = 6 * var4%y2(2)%y%x2(1)%x
153 var4%y2(2)%y%x2(2)%x = 6 * var4%y2(2)%y%x2(2)%x
154 endif
155 !$omp end target
156
157 else if (case == 2) then
158 ! Use target with defaultmap(TO)
159
160 !$omp target defaultmap(to : all)
161 if (any (var1%x /= [1,2,3,4])) stop 1
162 var1%x = 2 * var1%x
163 !$omp end target
164
165 !$omp target defaultmap(to : all)
166 if (any (var1a%x /= [-1,-2,-3,-4])) stop 2
167 var1a%x = 3 * var1a%x
168 !$omp end target
169
170 !$omp target defaultmap(to : all) ! { dg-warning "Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
171 if (any (var2%x /= [11,22,33,44])) stop 3
172 var2%x = 4 * var2%x
173 !$omp end target
174
175 !$omp target defaultmap(to : all) ! { dg-warning "Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
176 if (any (var3%x%x /= [111,222,333,444])) stop 4
177 var3%x%x = 5 * var3%x%x
178 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
179 if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 4
180 if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 4
181 var3%x2(1)%x = 5 * var3%x2(1)%x
182 var3%x2(2)%x = 5 * var3%x2(2)%x
183 endif
184 !$omp end target
185
186 !$omp target defaultmap(to : all) firstprivate(is_shared_mem) ! { dg-warning "Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
187 if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 5
188 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
189 if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 5
190 if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 5
191 endif
192 if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 5
193 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
194 if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 5
195 if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 5
196 endif
197 if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 5
198 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
199 if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 5
200 if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 5
201 endif
202 var4%y%y%x%x = 6 * var4%y%y%x%x
203 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
204 var4%y%y%x2(1)%x = 6 * var4%y%y%x2(1)%x
205 var4%y%y%x2(2)%x = 6 * var4%y%y%x2(2)%x
206 endif
207 var4%y2(1)%y%x%x = 6 * var4%y2(1)%y%x%x
208 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
209 var4%y2(1)%y%x2(1)%x = 6 * var4%y2(1)%y%x2(1)%x
210 var4%y2(1)%y%x2(2)%x = 6 * var4%y2(1)%y%x2(2)%x
211 endif
212 var4%y2(2)%y%x%x = 6 * var4%y2(2)%y%x%x
213 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
214 var4%y2(2)%y%x2(1)%x = 6 * var4%y2(2)%y%x2(1)%x
215 var4%y2(2)%y%x2(2)%x = 6 * var4%y2(2)%y%x2(2)%x
216 endif
217 !$omp end target
218
219 else if (case == 3) then
220 ! Use target with map clause
221
222 !$omp target map(tofrom: var1)
223 if (any (var1%x /= [1,2,3,4])) stop 1
224 var1%x = 2 * var1%x
225 !$omp end target
226
227 !$omp target map(tofrom: var1a)
228 if (any (var1a%x /= [-1,-2,-3,-4])) stop 2
229 var1a%x = 3 * var1a%x
230 !$omp end target
231
232 !$omp target map(tofrom: var2) ! { dg-warning "28: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
233 if (any (var2%x /= [11,22,33,44])) stop 3
234 var2%x = 4 * var2%x
235 !$omp end target
236
237 !$omp target map(tofrom: var3) ! { dg-warning "28: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
238 if (any (var3%x%x /= [111,222,333,444])) stop 4
239 var3%x%x = 5 * var3%x%x
240 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
241 if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 4
242 if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 4
243 var3%x2(1)%x = 5 * var3%x2(1)%x
244 var3%x2(2)%x = 5 * var3%x2(2)%x
245 endif
246 !$omp end target
247
248 !$omp target map(tofrom: var4) ! { dg-warning "28: Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
249 if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 5
250 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
251 if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 5
252 if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 5
253 end if
254 if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 5
255 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
256 if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 5
257 if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 5
258 endif
259 if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 5
260 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
261 if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 5
262 if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 5
263 endif
264 var4%y%y%x%x = 6 * var4%y%y%x%x
265 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
266 var4%y%y%x2(1)%x = 6 * var4%y%y%x2(1)%x
267 var4%y%y%x2(2)%x = 6 * var4%y%y%x2(2)%x
268 endif
269 var4%y2(1)%y%x%x = 6 * var4%y2(1)%y%x%x
270 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
271 var4%y2(1)%y%x2(1)%x = 6 * var4%y2(1)%y%x2(1)%x
272 var4%y2(1)%y%x2(2)%x = 6 * var4%y2(1)%y%x2(2)%x
273 endif
274 var4%y2(2)%y%x%x = 6 * var4%y2(2)%y%x%x
275 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
276 var4%y2(2)%y%x2(1)%x = 6 * var4%y2(2)%y%x2(1)%x
277 var4%y2(2)%y%x2(2)%x = 6 * var4%y2(2)%y%x2(2)%x
278 endif
279 !$omp end target
280
281 else if (case == 4) then
282 ! Use target with map clause -- NOTE: This uses TO not TOFROM
283
284 !$omp target map(to: var1)
285 if (any (var1%x /= [1,2,3,4])) stop 1
286 var1%x = 2 * var1%x
287 !$omp end target
288
289 !$omp target map(to: var1a)
290 if (any (var1a%x /= [-1,-2,-3,-4])) stop 2
291 var1a%x = 3 * var1a%x
292 !$omp end target
293
294 !$omp target map(to: var2) ! { dg-warning "24: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
295 if (any (var2%x /= [11,22,33,44])) stop 3
296 var2%x = 4 * var2%x
297 !$omp end target
298
299 !$omp target map(to: var3) ! { dg-warning "24: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
300 if (any (var3%x%x /= [111,222,333,444])) stop 4
301 var3%x%x = 5 * var3%x%x
302 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
303 if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 4
304 if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 4
305 var3%x2(1)%x = 5 * var3%x2(1)%x
306 var3%x2(2)%x = 5 * var3%x2(2)%x
307 endif
308 !$omp end target
309
310 !$omp target map(to: var4) ! { dg-warning "24: Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
311 if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 5
312 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
313 if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 5
314 if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 5
315 endif
316 if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 5
317 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
318 if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 5
319 if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 5
320 endif
321 if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 5
322 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
323 if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 5
324 if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 5
325 endif
326 var4%y%y%x%x = 6 * var4%y%y%x%x
327 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
328 var4%y%y%x2(1)%x = 6 * var4%y%y%x2(1)%x
329 var4%y%y%x2(2)%x = 6 * var4%y%y%x2(2)%x
330 endif
331 var4%y2(1)%y%x%x = 6 * var4%y2(1)%y%x%x
332 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
333 var4%y2(1)%y%x2(1)%x = 6 * var4%y2(1)%y%x2(1)%x
334 var4%y2(1)%y%x2(2)%x = 6 * var4%y2(1)%y%x2(2)%x
335 endif
336 var4%y2(2)%y%x%x = 6 * var4%y2(2)%y%x%x
337 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
338 var4%y2(2)%y%x2(1)%x = 6 * var4%y2(2)%y%x2(1)%x
339 var4%y2(2)%y%x2(2)%x = 6 * var4%y2(2)%y%x2(2)%x
340 endif
341 !$omp end target
342
343 else if (case == 5) then
344 ! Use target enter/exit data + target with explicit map
345 !$omp target enter data map(to: var1)
346 !$omp target enter data map(to: var1a)
347 !$omp target enter data map(to: var2) ! { dg-warning "35: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
348 !$omp target enter data map(to: var3) ! { dg-warning "35: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
349 !$omp target enter data map(to: var4) ! { dg-warning "35: Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
350
351 !$omp target map(to: var1)
352 if (any (var1%x /= [1,2,3,4])) stop 1
353 var1%x = 2 * var1%x
354 !$omp end target
355
356 !$omp target map(to: var1a)
357 if (any (var1a%x /= [-1,-2,-3,-4])) stop 2
358 var1a%x = 3 * var1a%x
359 !$omp end target
360
361 !$omp target map(to: var2) ! { dg-warning "24: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
362 if (any (var2%x /= [11,22,33,44])) stop 3
363 var2%x = 4 * var2%x
364 !$omp end target
365
366 !$omp target map(to: var3) ! { dg-warning "24: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
367 if (any (var3%x%x /= [111,222,333,444])) stop 4
368 var3%x%x = 5 * var3%x%x
369 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
370 if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 4
371 if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 4
372 var3%x2(1)%x = 5 * var3%x2(1)%x
373 var3%x2(2)%x = 5 * var3%x2(2)%x
374 endif
375 !$omp end target
376
377 !$omp target map(to: var4) ! { dg-warning "24: Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
378 if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 5
379 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
380 if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 5
381 if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 5
382 endif
383 if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 5
384 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
385 if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 5
386 if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 5
387 endif
388 if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 5
389 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
390 if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 5
391 if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 5
392 endif
393 var4%y%y%x%x = 6 * var4%y%y%x%x
394 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
395 var4%y%y%x2(1)%x = 6 * var4%y%y%x2(1)%x
396 var4%y%y%x2(2)%x = 6 * var4%y%y%x2(2)%x
397 endif
398 var4%y2(1)%y%x%x = 6 * var4%y2(1)%y%x%x
399 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
400 var4%y2(1)%y%x2(1)%x = 6 * var4%y2(1)%y%x2(1)%x
401 var4%y2(1)%y%x2(2)%x = 6 * var4%y2(1)%y%x2(2)%x
402 endif
403 var4%y2(2)%y%x%x = 6 * var4%y2(2)%y%x%x
404 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
405 var4%y2(2)%y%x2(1)%x = 6 * var4%y2(2)%y%x2(1)%x
406 var4%y2(2)%y%x2(2)%x = 6 * var4%y2(2)%y%x2(2)%x
407 endif
408 !$omp end target
409
410 !$omp target exit data map(from: var1)
411 !$omp target exit data map(from: var1a)
412 !$omp target exit data map(from: var2) ! { dg-warning "36: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
413 !$omp target exit data map(from: var3) ! { dg-warning "36: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
414 !$omp target exit data map(from: var4) ! { dg-warning "36: Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
415
416 else if (case == 6) then
417 ! Use target enter/exit data + target with implicit map
418
419 !$omp target enter data map(to: var1)
420 !$omp target enter data map(to: var1a)
421 !$omp target enter data map(to: var2) ! { dg-warning "35: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
422 !$omp target enter data map(to: var3) ! { dg-warning "35: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
423 !$omp target enter data map(to: var4) ! { dg-warning "35: Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
424
425 !$omp target
426 if (any (var1%x /= [1,2,3,4])) stop 1
427 var1%x = 2 * var1%x
428 !$omp end target
429
430 !$omp target
431 if (any (var1a%x /= [-1,-2,-3,-4])) stop 2
432 var1a%x = 3 * var1a%x
433 !$omp end target
434
435 !$omp target ! { dg-warning "Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
436 if (any (var2%x /= [11,22,33,44])) stop 3
437 var2%x = 4 * var2%x
438 !$omp end target
439
440 !$omp target ! { dg-warning "Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
441 if (any (var3%x%x /= [111,222,333,444])) stop 4
442 var3%x%x = 5 * var3%x%x
443 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
444 if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 4
445 if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 4
446 var3%x2(1)%x = 5 * var3%x2(1)%x
447 var3%x2(2)%x = 5 * var3%x2(2)%x
448 endif
449 !$omp end target
450
451 !$omp target ! { dg-warning "Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
452 if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 5
453 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
454 if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 5
455 if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 5
456 endif
457 if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 5
458 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
459 if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 5
460 if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 5
461 endif
462 if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 5
463 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
464 if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 5
465 if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 5
466 endif
467 var4%y%y%x%x = 6 * var4%y%y%x%x
468 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
469 var4%y%y%x2(1)%x = 6 * var4%y%y%x2(1)%x
470 var4%y%y%x2(2)%x = 6 * var4%y%y%x2(2)%x
471 endif
472 var4%y2(1)%y%x%x = 6 * var4%y2(1)%y%x%x
473 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
474 var4%y2(1)%y%x2(1)%x = 6 * var4%y2(1)%y%x2(1)%x
475 var4%y2(1)%y%x2(2)%x = 6 * var4%y2(1)%y%x2(2)%x
476 endif
477 var4%y2(2)%y%x%x = 6 * var4%y2(2)%y%x%x
478 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
479 var4%y2(2)%y%x2(1)%x = 6 * var4%y2(2)%y%x2(1)%x
480 var4%y2(2)%y%x2(2)%x = 6 * var4%y2(2)%y%x2(2)%x
481 endif
482 !$omp end target
483
484 !$omp target exit data map(from: var1)
485 !$omp target exit data map(from: var1a)
486 !$omp target exit data map(from: var2) ! { dg-warning "36: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
487 !$omp target exit data map(from: var3) ! { dg-warning "36: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
488 !$omp target exit data map(from: var4) ! { dg-warning "36: Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
489
490 else
491 error stop
492 end if
493
494 if ((case /= 2 .and. case /= 4) .or. is_shared_mem) then
495 ! The target update should have been active, check for the updated values
496 if (any (var1%x /= 2 * [1,2,3,4])) stop 11
497 if (any (var1a%x /= 3 * [-1,-2,-3,-4])) stop 22
498 if (any (var2%x /= 4 * [11,22,33,44])) stop 33
499
500 if (any (var3%x%x /= 5 * [111,222,333,444])) stop 44
501 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
502 if (any (var3%x2(1)%x /= 2 * 5 * [111,222,333,444])) stop 44
503 if (any (var3%x2(2)%x /= 3 * 5 * [111,222,333,444])) stop 44
504 endif
505
506 if (any (var4%y%y%x%x /= -1 * 6 * [1111,2222,3333,4444])) stop 55
507 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
508 if (any (var4%y%y%x2(1)%x /= -2 * 6 * [1111,2222,3333,4444])) stop 55
509 if (any (var4%y%y%x2(2)%x /= -3 * 6 * [1111,2222,3333,4444])) stop 55
510 endif
511 if (any (var4%y2(1)%y%x%x /= -4 * 6 * [1111,2222,3333,4444])) stop 55
512 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
513 if (any (var4%y2(1)%y%x2(1)%x /= -5 * 6 * [1111,2222,3333,4444])) stop 55
514 if (any (var4%y2(1)%y%x2(2)%x /= -6 * 6 * [1111,2222,3333,4444])) stop 55
515 endif
516 if (any (var4%y2(2)%y%x%x /= -7 * 6 * [1111,2222,3333,4444])) stop 55
517 if (is_shared_mem) then ! For stride data, this accesses the host's _vtab
518 if (any (var4%y2(2)%y%x2(1)%x /= -8 * 6 * [1111,2222,3333,4444])) stop 55
519 if (any (var4%y2(2)%y%x2(2)%x /= -9 * 6 * [1111,2222,3333,4444])) stop 55
520 endif
521 else
522 ! The old host values should still be there as 'to:' created a device copy
523 if (any (var1%x /= [1,2,3,4])) stop 12
524 if (any (var1a%x /= [-1,-2,-3,-4])) stop 22
525 if (any (var2%x /= [11,22,33,44])) stop 33
526
527 if (any (var3%x%x /= [111,222,333,444])) stop 44
528 ! .not. is_shared_mem:
529 ! if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 44
530 ! if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 44
531
532 if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 55
533 if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 55
534 if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 55
535 if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 55
536 ! .not. is_shared_mem:
537 !if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 55
538 !if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 55
539 if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 55
540 ! .not. is_shared_mem:
541 !if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 55
542 !if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 55
543 end if
544 if (case_var(100) /= 0) stop 123
545 end subroutine test
546
547 program main
548 use omp_lib
549 implicit none(type, external)
550 #ifdef USE_USM_REQUIREMENT
551 !$omp requires unified_shared_memory
552 #endif
553
554 interface
555 subroutine test(case)
556 integer, value :: case
557 end
558 end interface
559 integer :: dev
560 call run_it(omp_get_default_device())
561 do dev = 0, omp_get_num_devices()
562 call run_it(dev)
563 end do
564 call run_it(omp_initial_device)
565 ! print *, 'all done'
566 contains
567 subroutine run_it(dev)
568 integer, value :: dev
569 ! print *, 'DEVICE', dev
570 call omp_set_default_device(dev)
571 call test(1)
572 call test(2)
573 call test(3)
574 call test(4)
575 call test(5)
576 call test(6)
577 end
578 end