aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/map-alloc-comp-7.f90
blob: 1493c5fb03112b6420870c53b3cd57b4754c02c0 (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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
module m
  implicit none (type, external)
  type t
    integer, allocatable :: arr(:,:)
    integer :: var
    integer, allocatable :: slr
  end type t

contains

  subroutine check_it (is_present, dummy_alloced, inner_alloc, &
                       scalar, array, a_scalar, a_array, &
                       l_scalar, l_array, la_scalar, la_array, &
                       opt_scalar, opt_array, a_opt_scalar, a_opt_array)
    type(t), intent(inout) :: &
            scalar, array(:,:), opt_scalar, opt_array(:,:), a_scalar, a_array(:,:), &
            a_opt_scalar, a_opt_array(:,:), &
            l_scalar, l_array(:,:), la_scalar, la_array(:,:)
    optional :: opt_scalar, opt_array, a_opt_scalar, a_opt_array
    allocatable :: a_scalar, a_array, a_opt_scalar, a_opt_array, la_scalar, la_array
    logical, value :: is_present, dummy_alloced, inner_alloc
    integer :: i, j, k, l

    ! CHECK VALUE
    if (scalar%var /= 42) stop 1
    if (l_scalar%var /= 42) stop 1
    if (is_present) then
      if (opt_scalar%var /= 42) stop 2
    end if
    if (any (shape(array) /= [3,2])) stop 1
    if (any (shape(l_array) /= [3,2])) stop 1
    if (is_present) then
      if (any (shape(opt_array) /= [3,2])) stop 1
    end if
    do j = 1, 2
      do i = 1, 3
        if (array(i,j)%var /= i*97 + 100*41*j) stop 3
        if (l_array(i,j)%var /= i*97 + 100*41*j) stop 3
        if (is_present) then
          if (opt_array(i,j)%var /= i*97 + 100*41*j) stop 4
        end if
      end do
    end do

    if (dummy_alloced) then
      if (a_scalar%var /= 42) stop 1
      if (la_scalar%var /= 42) stop 1
      if (is_present) then
        if (a_opt_scalar%var /= 42) stop 1
      end if
      if (any (shape(a_array) /= [3,2])) stop 1
      if (any (shape(la_array) /= [3,2])) stop 1
      if (is_present) then
        if (any (shape(a_opt_array) /= [3,2])) stop 1
      end if
      do j = 1, 2
        do i = 1, 3
          if (a_array(i,j)%var /= i*97 + 100*41*j) stop 1
          if (la_array(i,j)%var /= i*97 + 100*41*j) stop 1
          if (is_present) then
            if (a_opt_array(i,j)%var /= i*97 + 100*41*j) stop 1
          end if
        end do
      end do
    else
      if (allocated (a_scalar)) stop 1
      if (allocated (la_scalar)) stop 1
      if (allocated (a_array)) stop 1
      if (allocated (la_array)) stop 1
      if (is_present) then
        if (allocated (a_opt_scalar)) stop 1
        if (allocated (a_opt_array)) stop 1
      end if
    end if

    if (inner_alloc) then
      if (scalar%slr /= 467) stop 5
      if (l_scalar%slr /= 467) stop 5
      if (a_scalar%slr /= 467) stop 6
      if (la_scalar%slr /= 467) stop 6
      if (is_present) then
        if (opt_scalar%slr /= 467) stop 7
        if (a_opt_scalar%slr /= 467) stop 8
      end if
      do j = 1, 2
        do i = 1, 3
          if (array(i,j)%slr /= (i*97 + 100*41*j)  + 467) stop 9
          if (l_array(i,j)%slr /= (i*97 + 100*41*j)  + 467) stop 9
          if (a_array(i,j)%slr /= (i*97 + 100*41*j)  + 467) stop 10
          if (la_array(i,j)%slr /= (i*97 + 100*41*j)  + 467) stop 10
          if (is_present) then
            if (opt_array(i,j)%slr /= (i*97 + 100*41*j)  + 467) stop 11
            if (a_opt_array(i,j)%slr /= (i*97 + 100*41*j)  + 467) stop 12
          end if
        end do
      end do

      do l = 1, 5
        do k = 1, 4
          if (any (shape(scalar%arr) /= [4,5])) stop 1
          if (any (shape(l_scalar%arr) /= [4,5])) stop 1
          if (any (shape(a_scalar%arr) /= [4,5])) stop 1
          if (any (shape(la_scalar%arr) /= [4,5])) stop 1
          if (scalar%arr(k,l) /= (i*27 + 1000*11*j) + 467) stop 13
          if (l_scalar%arr(k,l) /= (i*27 + 1000*11*j) + 467) stop 13
          if (a_scalar%arr(k,l) /= (i*27 + 1000*11*j) + 467) stop 14
          if (la_scalar%arr(k,l) /= (i*27 + 1000*11*j) + 467) stop 14
          if (is_present) then
            if (any (shape(opt_scalar%arr) /= [4,5])) stop 1
            if (any (shape(a_opt_scalar%arr) /= [4,5])) stop 1
            if (opt_scalar%arr(k,l) /= (i*27 + 1000*11*j) + 467) stop 15
            if (a_opt_scalar%arr(k,l) /= (i*27 + 1000*11*j) + 467) stop 16
          end if
        end do
      end do
      do j = 1, 2
        do i = 1, 3
          if (any (shape(array(i,j)%arr) /= [i,j])) stop 1
          if (any (shape(l_array(i,j)%arr) /= [i,j])) stop 1
          if (any (shape(a_array(i,j)%arr) /= [i,j])) stop 1
          if (any (shape(la_array(i,j)%arr) /= [i,j])) stop 1
          if (is_present) then
            if (any (shape(opt_array(i,j)%arr) /= [i,j])) stop 1
            if (any (shape(a_opt_array(i,j)%arr) /= [i,j])) stop 1
          endif
          do l = 1, j
            do k = 1, i
              if (array(i,j)%arr(k,l) /= i*27 + 1000*11*j + 467 + 3*k +53*l) stop 17
              if (l_array(i,j)%arr(k,l) /= i*27 + 1000*11*j + 467 + 3*k +53*l) stop 17
              if (a_array(i,j)%arr(k,l) /= i*27 + 1000*11*j + 467 + 3*k +53*l) stop 18
              if (la_array(i,j)%arr(k,l) /= i*27 + 1000*11*j + 467 + 3*k +53*l) stop 18
              if (is_present) then
                if (opt_array(i,j)%arr(k,l) /= i*27 + 1000*11*j + 467 + 3*k +53*l) stop 19
                if (a_opt_array(i,j)%arr(k,l) /= i*27 + 1000*11*j + 467 + 3*k +53*l) stop 20
              end if
            end do
          end do
        end do
      end do
    else if (dummy_alloced) then
      if (allocated (scalar%slr)) stop 1
      if (allocated (l_scalar%slr)) stop 1
      if (allocated (a_scalar%slr)) stop 1
      if (allocated (la_scalar%slr)) stop 1
      if (is_present) then
        if (allocated (opt_scalar%slr)) stop 1
        if (allocated (a_opt_scalar%slr)) stop 1
      endif
      if (allocated (scalar%arr)) stop 1
      if (allocated (l_scalar%arr)) stop 1
      if (allocated (a_scalar%arr)) stop 1
      if (allocated (la_scalar%arr)) stop 1
      if (is_present) then
        if (allocated (opt_scalar%arr)) stop 1
        if (allocated (a_opt_scalar%arr)) stop 1
      endif
    end if

    ! SET VALUE
    scalar%var = 42 + 13
    l_scalar%var = 42 + 13
    if (is_present) then
      opt_scalar%var = 42 + 13
    endif
    do j = 1, 2
      do i = 1, 3
        array(i,j)%var = i*97 + 100*41*j + 13
        l_array(i,j)%var = i*97 + 100*41*j + 13
        if (is_present) then
          opt_array(i,j)%var = i*97 + 100*41*j + 13
        end if
      end do
    end do

    if (dummy_alloced) then
      a_scalar%var = 42 + 13
      la_scalar%var = 42 + 13
      if (is_present) then
        a_opt_scalar%var = 42 + 13
      endif
      do j = 1, 2
        do i = 1, 3
          a_array(i,j)%var = i*97 + 100*41*j + 13
          la_array(i,j)%var = i*97 + 100*41*j + 13
          if (is_present) then
            a_opt_array(i,j)%var = i*97 + 100*41*j + 13
          endif
        end do
      end do
    end if

    if (inner_alloc) then
      scalar%slr = 467 + 13
      l_scalar%slr = 467 + 13
      a_scalar%slr = 467 + 13
      la_scalar%slr = 467 + 13
      if (is_present) then
        opt_scalar%slr = 467 + 13
        a_opt_scalar%slr = 467 + 13
      end if
      do j = 1, 2
        do i = 1, 3
          array(i,j)%slr = (i*97 + 100*41*j)  + 467 + 13
          l_array(i,j)%slr = (i*97 + 100*41*j)  + 467 + 13
          a_array(i,j)%slr = (i*97 + 100*41*j)  + 467 + 13
          la_array(i,j)%slr = (i*97 + 100*41*j)  + 467 + 13
          if (is_present) then
            opt_array(i,j)%slr = (i*97 + 100*41*j)  + 467 + 13
            a_opt_array(i,j)%slr = (i*97 + 100*41*j)  + 467 + 13
          end if
        end do
      end do

      do l = 1, 5
        do k = 1, 4
          scalar%arr(k,l) = (i*27 + 1000*11*j) + 467 + 13
          l_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467 + 13
          a_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467 + 13
          la_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467 + 13
          if (is_present) then
            opt_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467 + 13
            a_opt_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467 + 13
          end if
        end do
      end do
      do j = 1, 2
        do i = 1, 3
          do l = 1, j
            do k = 1, i
              array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l + 13
              l_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l + 13
              a_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l + 13
              la_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l + 13
              if (is_present) then
                opt_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l + 13
                a_opt_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l + 13
              end if
            end do
          end do
        end do
      end do
    end if

  end subroutine
  subroutine check_reset (is_present, dummy_alloced, inner_alloc, &
                          scalar, array, a_scalar, a_array, &
                          l_scalar, l_array, la_scalar, la_array, &
                          opt_scalar, opt_array, a_opt_scalar, a_opt_array)
    type(t), intent(inout) :: &
            scalar, array(:,:), opt_scalar, opt_array(:,:), a_scalar, a_array(:,:), &
            a_opt_scalar, a_opt_array(:,:), &
            l_scalar, l_array(:,:), la_scalar, la_array(:,:)
    optional :: opt_scalar, opt_array, a_opt_scalar, a_opt_array
    allocatable :: a_scalar, a_array, a_opt_scalar, a_opt_array, la_scalar, la_array
    logical, value :: is_present, dummy_alloced, inner_alloc
    integer :: i, j, k, l

    ! CHECK VALUE
    if (scalar%var /= 42 + 13) stop 1
    if (l_scalar%var /= 42 + 13) stop 1
    if (is_present) then
      if (opt_scalar%var /= 42 + 13) stop 2
    end if
    if (any (shape(array) /= [3,2])) stop 1
    if (any (shape(l_array) /= [3,2])) stop 1
    if (is_present) then
      if (any (shape(opt_array) /= [3,2])) stop 1
    end if
    do j = 1, 2
      do i = 1, 3
        if (array(i,j)%var /= i*97 + 100*41*j + 13) stop 3
        if (l_array(i,j)%var /= i*97 + 100*41*j + 13) stop 3
        if (is_present) then
          if (opt_array(i,j)%var /= i*97 + 100*41*j + 13) stop 4
        end if
      end do
    end do

    if (dummy_alloced) then
      if (a_scalar%var /= 42 + 13) stop 1
      if (la_scalar%var /= 42 + 13) stop 1
      if (is_present) then
        if (a_opt_scalar%var /= 42 + 13) stop 1
      end if
      if (any (shape(a_array) /= [3,2])) stop 1
      if (any (shape(la_array) /= [3,2])) stop 1
      if (is_present) then
        if (any (shape(a_opt_array) /= [3,2])) stop 1
      end if
      do j = 1, 2
        do i = 1, 3
          if (a_array(i,j)%var /= i*97 + 100*41*j + 13) stop 1
          if (la_array(i,j)%var /= i*97 + 100*41*j + 13) stop 1
          if (is_present) then
            if (a_opt_array(i,j)%var /= i*97 + 100*41*j + 13) stop 1
          end if
        end do
      end do
    else
      if (allocated (a_scalar)) stop 1
      if (allocated (la_scalar)) stop 1
      if (allocated (a_array)) stop 1
      if (allocated (la_array)) stop 1
      if (is_present) then
        if (allocated (a_opt_scalar)) stop 1
        if (allocated (a_opt_array)) stop 1
      end if
    end if

    if (inner_alloc) then
      if (scalar%slr /= 467 + 13) stop 5
      if (l_scalar%slr /= 467 + 13) stop 5
      if (a_scalar%slr /= 467 + 13) stop 6
      if (la_scalar%slr /= 467 + 13) stop 6
      if (is_present) then
        if (opt_scalar%slr /= 467 + 13) stop 7
        if (a_opt_scalar%slr /= 467 + 13) stop 8
      end if
      do j = 1, 2
        do i = 1, 3
          if (array(i,j)%slr /= (i*97 + 100*41*j)  + 467 + 13) stop 9
          if (l_array(i,j)%slr /= (i*97 + 100*41*j)  + 467 + 13) stop 9
          if (a_array(i,j)%slr /= (i*97 + 100*41*j)  + 467 + 13) stop 10
          if (la_array(i,j)%slr /= (i*97 + 100*41*j)  + 467 + 13) stop 10
          if (is_present) then
            if (opt_array(i,j)%slr /= (i*97 + 100*41*j)  + 467 + 13) stop 11
            if (a_opt_array(i,j)%slr /= (i*97 + 100*41*j)  + 467 + 13) stop 12
          end if
        end do
      end do

      do l = 1, 5
        do k = 1, 4
          if (any (shape(scalar%arr) /= [4,5])) stop 1
          if (any (shape(l_scalar%arr) /= [4,5])) stop 1
          if (any (shape(a_scalar%arr) /= [4,5])) stop 1
          if (any (shape(la_scalar%arr) /= [4,5])) stop 1
          if (scalar%arr(k,l) /= (i*27 + 1000*11*j) + 467 + 13) stop 13
          if (l_scalar%arr(k,l) /= (i*27 + 1000*11*j) + 467 + 13) stop 13
          if (a_scalar%arr(k,l) /= (i*27 + 1000*11*j) + 467 + 13) stop 14
          if (la_scalar%arr(k,l) /= (i*27 + 1000*11*j) + 467 + 13) stop 14
          if (is_present) then
            if (any (shape(opt_scalar%arr) /= [4,5])) stop 1
            if (any (shape(a_opt_scalar%arr) /= [4,5])) stop 1
            if (opt_scalar%arr(k,l) /= (i*27 + 1000*11*j) + 467 + 13) stop 15
            if (a_opt_scalar%arr(k,l) /= (i*27 + 1000*11*j) + 467 + 13) stop 16
          end if
        end do
      end do
      do j = 1, 2
        do i = 1, 3
          if (any (shape(array(i,j)%arr) /= [i,j])) stop 1
          if (any (shape(l_array(i,j)%arr) /= [i,j])) stop 1
          if (any (shape(a_array(i,j)%arr) /= [i,j])) stop 1
          if (any (shape(la_array(i,j)%arr) /= [i,j])) stop 1
          if (is_present) then
            if (any (shape(opt_array(i,j)%arr) /= [i,j])) stop 1
            if (any (shape(a_opt_array(i,j)%arr) /= [i,j])) stop 1
          endif
          do l = 1, j
            do k = 1, i
              if (array(i,j)%arr(k,l) /= i*27 + 1000*11*j + 467 + 3*k +53*l + 13) stop 17
              if (l_array(i,j)%arr(k,l) /= i*27 + 1000*11*j + 467 + 3*k +53*l + 13) stop 17
              if (a_array(i,j)%arr(k,l) /= i*27 + 1000*11*j + 467 + 3*k +53*l + 13) stop 18
              if (la_array(i,j)%arr(k,l) /= i*27 + 1000*11*j + 467 + 3*k +53*l + 13) stop 18
              if (is_present) then
                if (opt_array(i,j)%arr(k,l) /= i*27 + 1000*11*j + 467 + 3*k +53*l + 13) stop 19
                if (a_opt_array(i,j)%arr(k,l) /= i*27 + 1000*11*j + 467 + 3*k +53*l + 13) stop 20
              end if
            end do
          end do
        end do
      end do
    else if (dummy_alloced) then
      if (allocated (scalar%slr)) stop 1
      if (allocated (l_scalar%slr)) stop 1
      if (allocated (a_scalar%slr)) stop 1
      if (allocated (la_scalar%slr)) stop 1
      if (is_present) then
        if (allocated (opt_scalar%slr)) stop 1
        if (allocated (a_opt_scalar%slr)) stop 1
      endif
      if (allocated (scalar%arr)) stop 1
      if (allocated (l_scalar%arr)) stop 1
      if (allocated (a_scalar%arr)) stop 1
      if (allocated (la_scalar%arr)) stop 1
      if (is_present) then
        if (allocated (opt_scalar%arr)) stop 1
        if (allocated (a_opt_scalar%arr)) stop 1
      endif
    end if

    ! (RE)SET VALUE
    scalar%var = 42
    l_scalar%var = 42
    if (is_present) then
      opt_scalar%var = 42
    endif
    do j = 1, 2
      do i = 1, 3
        array(i,j)%var = i*97 + 100*41*j
        l_array(i,j)%var = i*97 + 100*41*j
        if (is_present) then
          opt_array(i,j)%var = i*97 + 100*41*j
        end if
      end do
    end do

    if (dummy_alloced) then
      a_scalar%var = 42
      la_scalar%var = 42
      if (is_present) then
        a_opt_scalar%var = 42
      endif
      do j = 1, 2
        do i = 1, 3
          a_array(i,j)%var = i*97 + 100*41*j
          la_array(i,j)%var = i*97 + 100*41*j
          if (is_present) then
            a_opt_array(i,j)%var = i*97 + 100*41*j
          endif
        end do
      end do
    end if

    if (inner_alloc) then
      scalar%slr = 467
      l_scalar%slr = 467
      a_scalar%slr = 467
      la_scalar%slr = 467
      if (is_present) then
        opt_scalar%slr = 467
        a_opt_scalar%slr = 467
      end if
      do j = 1, 2
        do i = 1, 3
          array(i,j)%slr = (i*97 + 100*41*j)  + 467
          l_array(i,j)%slr = (i*97 + 100*41*j)  + 467
          a_array(i,j)%slr = (i*97 + 100*41*j)  + 467
          la_array(i,j)%slr = (i*97 + 100*41*j)  + 467
          if (is_present) then
            opt_array(i,j)%slr = (i*97 + 100*41*j)  + 467
            a_opt_array(i,j)%slr = (i*97 + 100*41*j)  + 467
          end if
        end do
      end do

      do l = 1, 5
        do k = 1, 4
          scalar%arr(k,l) = (i*27 + 1000*11*j) + 467
          l_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467
          a_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467
          la_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467
          if (is_present) then
            opt_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467
            a_opt_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467
          end if
        end do
      end do
      do j = 1, 2
        do i = 1, 3
          do l = 1, j
            do k = 1, i
              array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l
              l_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l
              a_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l
              la_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l
              if (is_present) then
                opt_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l
                a_opt_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l
              end if
            end do
          end do
        end do
      end do
    end if
  end subroutine

  subroutine test(scalar, array, a_scalar, a_array, opt_scalar, opt_array, &
                  a_opt_scalar, a_opt_array)
    type(t) :: scalar, array(:,:), opt_scalar, opt_array(:,:), a_scalar, a_array(:,:)
    type(t) :: a_opt_scalar, a_opt_array(:,:)
    type(t) :: l_scalar, l_array(3,2), la_scalar, la_array(:,:)
    allocatable :: a_scalar, a_array, a_opt_scalar, a_opt_array, la_scalar, la_array
    optional :: opt_scalar, opt_array, a_opt_scalar, a_opt_array

    integer :: i, j, k, l
    logical :: is_present, dummy_alloced, local_alloced, inner_alloc
    is_present = present(opt_scalar)
    dummy_alloced = allocated(a_scalar)
    inner_alloc = allocated(scalar%slr)

    l_scalar%var = 42
    do j = 1, 2
      do i = 1, 3
        l_array(i,j)%var = i*97 + 100*41*j
      end do
    end do

    if (dummy_alloced) then
      allocate(la_scalar, la_array(3,2))
      a_scalar%var = 42
      la_scalar%var = 42
      do j = 1, 2
        do i = 1, 3
          l_array(i,j)%var = i*97 + 100*41*j
          la_array(i,j)%var = i*97 + 100*41*j
        end do
      end do
    end if

    if (inner_alloc) then
      l_scalar%slr = 467
      la_scalar%slr = 467
      do j = 1, 2
        do i = 1, 3
          l_array(i,j)%slr = (i*97 + 100*41*j)  + 467
          la_array(i,j)%slr = (i*97 + 100*41*j)  + 467
        end do
      end do

      allocate(l_scalar%arr(4,5), la_scalar%arr(4,5))
      do l = 1, 5
        do k = 1, 4
          l_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467
          la_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467
        end do
      end do
      do j = 1, 2
        do i = 1, 3
          allocate(l_array(i,j)%arr(i,j), la_array(i,j)%arr(i,j))
          do l = 1, j
            do k = 1, i
              l_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l
              la_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l
            end do
          end do
        end do
      end do
    end if

    ! implicit mapping
    !$omp target
      if (is_present) then
        call check_it (is_present, dummy_alloced, inner_alloc, &
                       scalar, array, a_scalar, a_array, &
                       l_scalar, l_array, la_scalar, la_array, &
                       opt_scalar, opt_array, a_opt_scalar, a_opt_array)
      else
        call check_it (is_present, dummy_alloced, inner_alloc, &
                       scalar, array, a_scalar, a_array, &
                       l_scalar, l_array, la_scalar, la_array)
      end if
    !$omp end target

    if (is_present) then
      call check_reset (is_present, dummy_alloced, inner_alloc, &
                        scalar, array, a_scalar, a_array, &
                        l_scalar, l_array, la_scalar, la_array, &
                        opt_scalar, opt_array, a_opt_scalar, a_opt_array)
    else
      call check_reset (is_present, dummy_alloced, inner_alloc, &
                        scalar, array, a_scalar, a_array, &
                        l_scalar, l_array, la_scalar, la_array)
    endif

    ! explicit mapping
    !$omp target map(scalar, array, opt_scalar, opt_array, a_scalar, a_array) &
    !$omp&       map(a_opt_scalar, a_opt_array) &
    !$omp&       map(l_scalar, l_array, la_scalar, la_array)
      if (is_present) then
        call check_it (is_present, dummy_alloced, inner_alloc, &
                       scalar, array, a_scalar, a_array, &
                       l_scalar, l_array, la_scalar, la_array, &
                       opt_scalar, opt_array, a_opt_scalar, a_opt_array)
      else
        call check_it (is_present, dummy_alloced, inner_alloc, &
                       scalar, array, a_scalar, a_array, &
                       l_scalar, l_array, la_scalar, la_array)
      endif
    !$omp end target

    if (is_present) then
      call check_reset (is_present, dummy_alloced, inner_alloc, &
                        scalar, array, a_scalar, a_array, &
                        l_scalar, l_array, la_scalar, la_array, &
                        opt_scalar, opt_array, a_opt_scalar, a_opt_array)
    else
      call check_reset (is_present, dummy_alloced, inner_alloc, &
                        scalar, array, a_scalar, a_array, &
                        l_scalar, l_array, la_scalar, la_array)
    endif
  end subroutine
end module

program main
  use m
  implicit none (type, external)
  type(t) :: scalar, array(3,2), opt_scalar, opt_array(3,2), a_scalar, a_array(:,:)
  type(t) :: a_opt_scalar, a_opt_array(:,:)
  allocatable :: a_scalar, a_array, a_opt_scalar, a_opt_array
  integer :: i, j, k, l, n

  scalar%var = 42
  opt_scalar%var = 42
  do j = 1, 2
    do i = 1, 3
      array(i,j)%var = i*97 + 100*41*j
      opt_array(i,j)%var = i*97 + 100*41*j
    end do
  end do

  ! unallocated
  call test (scalar, array, a_scalar, a_array)
  call test (scalar, array, a_scalar, a_array, opt_scalar, opt_array, a_opt_scalar, a_opt_array)

  ! allocated
  allocate(a_scalar, a_opt_scalar, a_array(3,2), a_opt_array(3,2))
  a_scalar%var = 42
  a_opt_scalar%var = 42
  do j = 1, 2
    do i = 1, 3
      a_array(i,j)%var = i*97 + 100*41*j
      a_opt_array(i,j)%var = i*97 + 100*41*j
    end do
  end do

  call test (scalar, array, a_scalar, a_array)
  call test (scalar, array, a_scalar, a_array, opt_scalar, opt_array, a_opt_scalar, a_opt_array)

  ! comps allocated
  scalar%slr = 467
  a_scalar%slr = 467
  opt_scalar%slr = 467
  a_opt_scalar%slr = 467
  do j = 1, 2
    do i = 1, 3
      array(i,j)%slr = (i*97 + 100*41*j)  + 467
      a_array(i,j)%slr = (i*97 + 100*41*j)  + 467
      opt_array(i,j)%slr = (i*97 + 100*41*j)  + 467
      a_opt_array(i,j)%slr = (i*97 + 100*41*j)  + 467
    end do
  end do

  allocate(scalar%arr(4,5), a_scalar%arr(4,5), opt_scalar%arr(4,5), a_opt_scalar%arr(4,5))
  do l = 1, 5
    do k = 1, 4
      scalar%arr(k,l) = (i*27 + 1000*11*j) + 467
      a_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467
      opt_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467
      a_opt_scalar%arr(k,l) = (i*27 + 1000*11*j) + 467
    end do
  end do
  do j = 1, 2
    do i = 1, 3
      allocate(array(i,j)%arr(i,j), a_array(i,j)%arr(i,j), opt_array(i,j)%arr(i,j), a_opt_array(i,j)%arr(i,j))
      do l = 1, j
        do k = 1, i
          array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l
          a_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l
          opt_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l
          a_opt_array(i,j)%arr(k,l) = i*27 + 1000*11*j + 467 + 3*k +53*l
        end do
      end do
    end do
  end do

  call test (scalar, array, a_scalar, a_array)
  call test (scalar, array, a_scalar, a_array, opt_scalar, opt_array, a_opt_scalar, a_opt_array)

  deallocate(a_scalar, a_opt_scalar, a_array, a_opt_array)
end