1 /* PR middle-end/110270 */
3 /* OpenMP 5.2's 'defaultmap(default : pointer) for C/C++ pointers retains the
4 pointer value instead of setting it to NULL if the pointer cannot be found.
5 Contrary to requires-unified-addr-1.c which is valid OpenMP 5.0/5.1/5.2,
6 this testcase is only valid since OpenMP 5.2. */
8 /* This is kind of a follow-up to the requires-unified-addr-1.c testcase
9 and PR libgomp/109837 */
17 #pragma omp requires unified_address
31 s
.ptr
= (int *) omp_target_alloc (sizeof (int)*s
.n
, dev
);
32 int *ptr1
= (int *) omp_target_alloc (sizeof (int)*N
, dev
);
33 assert (s
.ptr
!= NULL
);
34 assert (ptr1
!= NULL
);
38 #pragma omp target enter data map(q) device(device_num: dev)
39 #pragma omp target data use_device_addr(q) device(device_num: dev)
42 #pragma omp target map(to:s) device(device_num: dev)
43 for (int i
= 0; i
< s
.n
; i
++)
46 int *ptr2
= &s
.ptr
[3];
48 /* s.ptr is not mapped (but omp_target_alloc'ed) thus ptr2 shall retain its value. */
49 #pragma omp target device(device_num: dev) /* implied: defaultmap(default : pointer) */
50 for (int i
= 0; i
< 4; i
++)
53 #pragma omp target exit data map(q) device(device_num: dev)
54 for (int i
= 0; i
< 4; i
++)
57 /* ptr1 retains the value as it is not mapped (but it is omp_target_alloc'ed). */
58 #pragma omp target defaultmap(default : pointer) device(device_num: dev)
59 for (int i
= 0; i
< N
; i
++)
62 int *ptr3
= (int *) malloc (sizeof (int)*N
);
63 assert (0 == omp_target_memcpy(ptr3
, ptr1
, N
* sizeof(int), 0, 0,
64 omp_get_initial_device(), dev
));
65 for (int i
= 0; i
< N
; i
++)
66 assert (ptr3
[i
] == 11*i
);
69 omp_target_free (ptr1
, dev
);
70 omp_target_free (s
.ptr
, dev
);
76 int ntgts
= omp_get_num_devices();
78 fprintf (stderr
, "Offloading devices exist\n"); /* { dg-output "Offloading devices exist(\n|\r\n|\r)" { target offload_device } } */
80 fprintf (stderr
, "Only host fallback\n"); /* { dg-output "Only host fallback(\n|\r\n|\r)" { target { ! offload_device } } } */
82 for (int i
= 0; i
<= ntgts
; i
++)