aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/map-alloc-comp-9.f90
blob: 3cec39218f567295bce4bc5a91e486eb32e149c0 (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
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
! Ensure that polymorphic mapping is diagnosed as undefined behavior
! Ensure that static access to polymorphic variables works

subroutine test(case)
implicit none(type, external)
type t
  integer :: x(4)
end type t

type ta
  integer, allocatable :: x(:)
end type ta

type t2
  class(t), allocatable :: x
  class(t), allocatable :: x2(:)
end type t2

type t3
   type(t2) :: y
   type(t2) :: y2(2)
end type t3

type t4
   type(t3), allocatable :: y
   type(t3), allocatable :: y2(:)
end type t4

integer, value :: case

logical :: is_shared_mem

! Mangle stack addresses
integer, volatile :: case_var(100*case)

type(t), allocatable :: var1
type(ta), allocatable :: var1a
class(t), allocatable :: var2
type(t2), allocatable :: var3
type(t4), allocatable :: var4

case_var(100) = 0
!print *, 'case', case

var1 = t([1,2,3,4])
var1a = ta([-1,-2,-3,-4,-5])

var2 = t([11,22,33,44])

allocate(t2 :: var3)
allocate(t  :: var3%x)
allocate(t  :: var3%x2(2))
var3%x%x = [111,222,333,444]
var3%x2(1)%x = 2*[111,222,333,444]
var3%x2(2)%x = 3*[111,222,333,444]

allocate(t4 :: var4)
allocate(t3 :: var4%y)
allocate(t3 :: var4%y2(2))
allocate(t :: var4%y%y%x)
allocate(t :: var4%y%y%x2(2))
allocate(t :: var4%y2(1)%y%x)
allocate(t :: var4%y2(1)%y%x2(2))
allocate(t :: var4%y2(2)%y%x)
allocate(t :: var4%y2(2)%y%x2(2))
var4%y%y%x%x = -1 * [1111,2222,3333,4444]
var4%y%y%x2(1)%x = -2 * [1111,2222,3333,4444]
var4%y%y%x2(2)%x = -3 * [1111,2222,3333,4444]
var4%y2(1)%y%x%x = -4 * [1111,2222,3333,4444]
var4%y2(1)%y%x2(1)%x = -5 * [1111,2222,3333,4444]
var4%y2(1)%y%x2(2)%x = -6 * [1111,2222,3333,4444]
var4%y2(2)%y%x%x = -7 * [1111,2222,3333,4444]
var4%y2(2)%y%x2(1)%x = -8 * [1111,2222,3333,4444]
var4%y2(2)%y%x2(2)%x = -9 * [1111,2222,3333,4444]

is_shared_mem = .false.
!$omp target map(to: is_shared_mem)
  is_shared_mem = .true.
!$omp end target

if (case == 1) then
  ! implicit mapping
  !$omp target
    if (any (var1%x /= [1,2,3,4])) stop 1
    var1%x = 2 * var1%x
  !$omp end target

  !$omp target
    if (any (var1a%x /= [-1,-2,-3,-4])) stop 2
    var1a%x = 3 * var1a%x
  !$omp end target

  !$omp target  ! { dg-warning "Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var2%x /= [11,22,33,44])) stop 3
    var2%x = 4 * var2%x
  !$omp end target

  !$omp target  ! { dg-warning "Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var3%x%x /= [111,222,333,444])) stop 4
    var3%x%x = 5 * var3%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 4
      if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 4
      var3%x2(1)%x = 5 * var3%x2(1)%x
      var3%x2(2)%x = 5 * var3%x2(2)%x
    end if
  !$omp end target

  !$omp target  ! { dg-warning "Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 5
    endif
    if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 5
    endif
    if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 5
    end if
    var4%y%y%x%x = 6 * var4%y%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y%y%x2(1)%x = 6 * var4%y%y%x2(1)%x
      var4%y%y%x2(2)%x = 6 * var4%y%y%x2(2)%x
    endif
    var4%y2(1)%y%x%x = 6 * var4%y2(1)%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y2(1)%y%x2(1)%x = 6 * var4%y2(1)%y%x2(1)%x
      var4%y2(1)%y%x2(2)%x = 6 * var4%y2(1)%y%x2(2)%x
    endif
    var4%y2(2)%y%x%x = 6 * var4%y2(2)%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y2(2)%y%x2(1)%x = 6 * var4%y2(2)%y%x2(1)%x
      var4%y2(2)%y%x2(2)%x = 6 * var4%y2(2)%y%x2(2)%x
    endif
  !$omp end target

else if (case == 2) then
  ! Use target with defaultmap(TO)

  !$omp target defaultmap(to : all)
    if (any (var1%x /= [1,2,3,4])) stop 1
    var1%x = 2 * var1%x
  !$omp end target

  !$omp target defaultmap(to : all)
    if (any (var1a%x /= [-1,-2,-3,-4])) stop 2
    var1a%x = 3 * var1a%x
  !$omp end target

  !$omp target defaultmap(to : all) ! { dg-warning "Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var2%x /= [11,22,33,44])) stop 3
    var2%x = 4 * var2%x
  !$omp end target

  !$omp target defaultmap(to : all)  ! { dg-warning "Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var3%x%x /= [111,222,333,444])) stop 4
    var3%x%x = 5 * var3%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 4
      if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 4
      var3%x2(1)%x = 5 * var3%x2(1)%x
      var3%x2(2)%x = 5 * var3%x2(2)%x
    endif
  !$omp end target

  !$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\\\]" }
    if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 5
    endif
    if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 5
    endif
    if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 5
    endif
    var4%y%y%x%x = 6 * var4%y%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y%y%x2(1)%x = 6 * var4%y%y%x2(1)%x
      var4%y%y%x2(2)%x = 6 * var4%y%y%x2(2)%x
    endif
    var4%y2(1)%y%x%x = 6 * var4%y2(1)%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y2(1)%y%x2(1)%x = 6 * var4%y2(1)%y%x2(1)%x
      var4%y2(1)%y%x2(2)%x = 6 * var4%y2(1)%y%x2(2)%x
    endif
    var4%y2(2)%y%x%x = 6 * var4%y2(2)%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y2(2)%y%x2(1)%x = 6 * var4%y2(2)%y%x2(1)%x
      var4%y2(2)%y%x2(2)%x = 6 * var4%y2(2)%y%x2(2)%x
    endif
  !$omp end target

else if (case == 3) then
  ! Use target with map clause

  !$omp target map(tofrom: var1)
    if (any (var1%x /= [1,2,3,4])) stop 1
    var1%x = 2 * var1%x
  !$omp end target

  !$omp target map(tofrom: var1a)
    if (any (var1a%x /= [-1,-2,-3,-4])) stop 2
    var1a%x = 3 * var1a%x
  !$omp end target

  !$omp target map(tofrom: var2)  ! { dg-warning "28: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var2%x /= [11,22,33,44])) stop 3
    var2%x = 4 * var2%x
  !$omp end target

  !$omp target map(tofrom: var3)  ! { dg-warning "28: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var3%x%x /= [111,222,333,444])) stop 4
    var3%x%x = 5 * var3%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 4
      if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 4
      var3%x2(1)%x = 5 * var3%x2(1)%x
      var3%x2(2)%x = 5 * var3%x2(2)%x
    endif
  !$omp end target

  !$omp target map(tofrom: var4)  ! { dg-warning "28: Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 5
    end if
    if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 5
    endif
    if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 5
    endif
    var4%y%y%x%x = 6 * var4%y%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y%y%x2(1)%x = 6 * var4%y%y%x2(1)%x
      var4%y%y%x2(2)%x = 6 * var4%y%y%x2(2)%x
    endif
    var4%y2(1)%y%x%x = 6 * var4%y2(1)%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y2(1)%y%x2(1)%x = 6 * var4%y2(1)%y%x2(1)%x
      var4%y2(1)%y%x2(2)%x = 6 * var4%y2(1)%y%x2(2)%x
    endif
    var4%y2(2)%y%x%x = 6 * var4%y2(2)%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y2(2)%y%x2(1)%x = 6 * var4%y2(2)%y%x2(1)%x
      var4%y2(2)%y%x2(2)%x = 6 * var4%y2(2)%y%x2(2)%x
    endif
  !$omp end target

else if (case == 4) then
  ! Use target with map clause -- NOTE: This uses TO not TOFROM

  !$omp target map(to: var1)
    if (any (var1%x /= [1,2,3,4])) stop 1
    var1%x = 2 * var1%x
  !$omp end target

  !$omp target map(to: var1a)
    if (any (var1a%x /= [-1,-2,-3,-4])) stop 2
    var1a%x = 3 * var1a%x
  !$omp end target

  !$omp target map(to: var2)  ! { dg-warning "24: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var2%x /= [11,22,33,44])) stop 3
    var2%x = 4 * var2%x
  !$omp end target

  !$omp target map(to: var3)  ! { dg-warning "24: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var3%x%x /= [111,222,333,444])) stop 4
    var3%x%x = 5 * var3%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 4
      if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 4
      var3%x2(1)%x = 5 * var3%x2(1)%x
      var3%x2(2)%x = 5 * var3%x2(2)%x
    endif
  !$omp end target

  !$omp target map(to: var4)  ! { dg-warning "24: Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 5
    endif
    if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 5
    endif
    if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 5
    endif
    var4%y%y%x%x = 6 * var4%y%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y%y%x2(1)%x = 6 * var4%y%y%x2(1)%x
      var4%y%y%x2(2)%x = 6 * var4%y%y%x2(2)%x
    endif
    var4%y2(1)%y%x%x = 6 * var4%y2(1)%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y2(1)%y%x2(1)%x = 6 * var4%y2(1)%y%x2(1)%x
      var4%y2(1)%y%x2(2)%x = 6 * var4%y2(1)%y%x2(2)%x
    endif
    var4%y2(2)%y%x%x = 6 * var4%y2(2)%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y2(2)%y%x2(1)%x = 6 * var4%y2(2)%y%x2(1)%x
      var4%y2(2)%y%x2(2)%x = 6 * var4%y2(2)%y%x2(2)%x
    endif
  !$omp end target

else if (case == 5) then
  ! Use target enter/exit data + target with explicit map
  !$omp target enter data map(to: var1)
  !$omp target enter data map(to: var1a)
  !$omp target enter data map(to: var2)  ! { dg-warning "35: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
  !$omp target enter data map(to: var3)  ! { dg-warning "35: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
  !$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\\\]" }

  !$omp target map(to: var1)
    if (any (var1%x /= [1,2,3,4])) stop 1
    var1%x = 2 * var1%x
  !$omp end target

  !$omp target map(to: var1a)
    if (any (var1a%x /= [-1,-2,-3,-4])) stop 2
    var1a%x = 3 * var1a%x
  !$omp end target

  !$omp target map(to: var2)  ! { dg-warning "24: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var2%x /= [11,22,33,44])) stop 3
    var2%x = 4 * var2%x
  !$omp end target

  !$omp target map(to: var3)  ! { dg-warning "24: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var3%x%x /= [111,222,333,444])) stop 4
    var3%x%x = 5 * var3%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 4
      if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 4
      var3%x2(1)%x = 5 * var3%x2(1)%x
      var3%x2(2)%x = 5 * var3%x2(2)%x
    endif
  !$omp end target

  !$omp target map(to: var4)  ! { dg-warning "24: Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 5
    endif
    if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 5
    endif
    if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 5
    endif
    var4%y%y%x%x = 6 * var4%y%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y%y%x2(1)%x = 6 * var4%y%y%x2(1)%x
      var4%y%y%x2(2)%x = 6 * var4%y%y%x2(2)%x
    endif
    var4%y2(1)%y%x%x = 6 * var4%y2(1)%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y2(1)%y%x2(1)%x = 6 * var4%y2(1)%y%x2(1)%x
      var4%y2(1)%y%x2(2)%x = 6 * var4%y2(1)%y%x2(2)%x
    endif
    var4%y2(2)%y%x%x = 6 * var4%y2(2)%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y2(2)%y%x2(1)%x = 6 * var4%y2(2)%y%x2(1)%x
      var4%y2(2)%y%x2(2)%x = 6 * var4%y2(2)%y%x2(2)%x
    endif
  !$omp end target

  !$omp target exit data map(from: var1)
  !$omp target exit data map(from: var1a)
  !$omp target exit data map(from: var2)  ! { dg-warning "36: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
  !$omp target exit data map(from: var3)  ! { dg-warning "36: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
  !$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\\\]" }

else if (case == 6) then
  ! Use target enter/exit data + target with implicit map

  !$omp target enter data map(to: var1)
  !$omp target enter data map(to: var1a)
  !$omp target enter data map(to: var2)  ! { dg-warning "35: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
  !$omp target enter data map(to: var3)  ! { dg-warning "35: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
  !$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\\\]" }

  !$omp target
    if (any (var1%x /= [1,2,3,4])) stop 1
    var1%x = 2 * var1%x
  !$omp end target

  !$omp target
    if (any (var1a%x /= [-1,-2,-3,-4])) stop 2
    var1a%x = 3 * var1a%x
  !$omp end target

  !$omp target  ! { dg-warning "Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var2%x /= [11,22,33,44])) stop 3
    var2%x = 4 * var2%x
  !$omp end target

  !$omp target  ! { dg-warning "Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var3%x%x /= [111,222,333,444])) stop 4
    var3%x%x = 5 * var3%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 4
      if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 4
      var3%x2(1)%x = 5 * var3%x2(1)%x
      var3%x2(2)%x = 5 * var3%x2(2)%x
    endif
  !$omp end target

  !$omp target  ! { dg-warning "Mapping of polymorphic list item 'var4\.\[0-9\]+->y->y\.x' is unspecified behavior \\\[-Wopenmp\\\]" }
    if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 5
    endif
    if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 5
    endif
    if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 5
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 5
      if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 5
    endif
    var4%y%y%x%x = 6 * var4%y%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y%y%x2(1)%x = 6 * var4%y%y%x2(1)%x
      var4%y%y%x2(2)%x = 6 * var4%y%y%x2(2)%x
    endif
    var4%y2(1)%y%x%x = 6 * var4%y2(1)%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y2(1)%y%x2(1)%x = 6 * var4%y2(1)%y%x2(1)%x
      var4%y2(1)%y%x2(2)%x = 6 * var4%y2(1)%y%x2(2)%x
    endif
    var4%y2(2)%y%x%x = 6 * var4%y2(2)%y%x%x
    if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
      var4%y2(2)%y%x2(1)%x = 6 * var4%y2(2)%y%x2(1)%x
      var4%y2(2)%y%x2(2)%x = 6 * var4%y2(2)%y%x2(2)%x
    endif
  !$omp end target

  !$omp target exit data map(from: var1)
  !$omp target exit data map(from: var1a)
  !$omp target exit data map(from: var2)  ! { dg-warning "36: Mapping of polymorphic list item 'var2' is unspecified behavior \\\[-Wopenmp\\\]" }
  !$omp target exit data map(from: var3)  ! { dg-warning "36: Mapping of polymorphic list item 'var3->x' is unspecified behavior \\\[-Wopenmp\\\]" }
  !$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\\\]" }

else
  error stop
end if

if ((case /= 2 .and. case /= 4)  .or. is_shared_mem) then
  ! The target update should have been active, check for the updated values
  if (any (var1%x /= 2 * [1,2,3,4])) stop 11
  if (any (var1a%x /= 3 * [-1,-2,-3,-4])) stop 22
  if (any (var2%x /= 4 * [11,22,33,44])) stop 33

  if (any (var3%x%x /= 5 * [111,222,333,444])) stop 44
  if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
    if (any (var3%x2(1)%x /= 2 * 5 * [111,222,333,444])) stop 44
    if (any (var3%x2(2)%x /= 3 * 5 * [111,222,333,444])) stop 44
  endif

  if (any (var4%y%y%x%x /= -1 * 6 * [1111,2222,3333,4444])) stop 55
  if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
    if (any (var4%y%y%x2(1)%x /= -2 * 6 * [1111,2222,3333,4444])) stop 55
    if (any (var4%y%y%x2(2)%x /= -3 * 6 * [1111,2222,3333,4444])) stop 55
  endif
  if (any (var4%y2(1)%y%x%x /= -4 * 6 * [1111,2222,3333,4444])) stop 55
  if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
    if (any (var4%y2(1)%y%x2(1)%x /= -5 * 6 * [1111,2222,3333,4444])) stop 55
    if (any (var4%y2(1)%y%x2(2)%x /= -6 * 6 * [1111,2222,3333,4444])) stop 55
  endif
  if (any (var4%y2(2)%y%x%x /= -7 * 6 * [1111,2222,3333,4444])) stop 55
  if (is_shared_mem) then  ! For stride data, this accesses the host's _vtab
    if (any (var4%y2(2)%y%x2(1)%x /= -8 * 6 * [1111,2222,3333,4444])) stop 55
    if (any (var4%y2(2)%y%x2(2)%x /= -9 * 6 * [1111,2222,3333,4444])) stop 55
  endif
else
  ! The old host values should still be there as 'to:' created a device copy
  if (any (var1%x /= [1,2,3,4])) stop 12
  if (any (var1a%x /= [-1,-2,-3,-4])) stop 22
  if (any (var2%x /= [11,22,33,44])) stop 33

  if (any (var3%x%x /= [111,222,333,444])) stop 44
  ! .not. is_shared_mem:
  ! if (any (var3%x2(1)%x /= 2*[111,222,333,444])) stop 44
  ! if (any (var3%x2(2)%x /= 3*[111,222,333,444])) stop 44

  if (any (var4%y%y%x%x /= -1 * [1111,2222,3333,4444])) stop 55
  if (any (var4%y%y%x2(1)%x /= -2 * [1111,2222,3333,4444])) stop 55
  if (any (var4%y%y%x2(2)%x /= -3 * [1111,2222,3333,4444])) stop 55
  if (any (var4%y2(1)%y%x%x /= -4 * [1111,2222,3333,4444])) stop 55
  ! .not. is_shared_mem:
  !if (any (var4%y2(1)%y%x2(1)%x /= -5 * [1111,2222,3333,4444])) stop 55
  !if (any (var4%y2(1)%y%x2(2)%x /= -6 * [1111,2222,3333,4444])) stop 55
  if (any (var4%y2(2)%y%x%x /= -7 * [1111,2222,3333,4444])) stop 55
  ! .not. is_shared_mem:
  !if (any (var4%y2(2)%y%x2(1)%x /= -8 * [1111,2222,3333,4444])) stop 55
  !if (any (var4%y2(2)%y%x2(2)%x /= -9 * [1111,2222,3333,4444])) stop 55
end if
if (case_var(100) /= 0) stop 123
end subroutine test

program main
  use omp_lib
  implicit none(type, external)
  interface
    subroutine test(case)
      integer, value :: case
    end
  end interface
  integer :: dev
  call run_it(omp_get_default_device())
  do dev = 0, omp_get_num_devices()
    call run_it(dev)
  end do
  call run_it(omp_initial_device)
!  print *, 'all done'
contains
subroutine run_it(dev)
  integer, value :: dev
!  print *, 'DEVICE', dev
  call omp_set_default_device(dev)
  call test(1)
  call test(2)
  call test(3)
  call test(4)
  call test(5)
  call test(6)
end
end