xref: /llvm-project/offload/test/mapping/present/zero_length_array_section.c (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1*330d8983SJohannes Doerfert // RUN: %libomptarget-compile-generic
2*330d8983SJohannes Doerfert // RUN: %libomptarget-run-fail-generic 2>&1 \
3*330d8983SJohannes Doerfert // RUN: | %fcheck-generic
4*330d8983SJohannes Doerfert 
5*330d8983SJohannes Doerfert #include <stdio.h>
6*330d8983SJohannes Doerfert 
main()7*330d8983SJohannes Doerfert int main() {
8*330d8983SJohannes Doerfert   int arr[5];
9*330d8983SJohannes Doerfert 
10*330d8983SJohannes Doerfert   // CHECK: addr=0x[[#%x,HOST_ADDR:]]
11*330d8983SJohannes Doerfert   fprintf(stderr, "addr=%p\n", arr);
12*330d8983SJohannes Doerfert 
13*330d8983SJohannes Doerfert   // CHECK-NOT: omptarget
14*330d8983SJohannes Doerfert #pragma omp target data map(alloc : arr[0 : 5])
15*330d8983SJohannes Doerfert #pragma omp target map(present, alloc : arr[0 : 0])
16*330d8983SJohannes Doerfert   ;
17*330d8983SJohannes Doerfert 
18*330d8983SJohannes Doerfert   // CHECK: arr is present
19*330d8983SJohannes Doerfert   fprintf(stderr, "arr is present\n");
20*330d8983SJohannes Doerfert 
21*330d8983SJohannes Doerfert   // arr[0:0] doesn't create an actual mapping in the first directive.
22*330d8983SJohannes Doerfert   //
23*330d8983SJohannes Doerfert   // CHECK: omptarget message: device mapping required by 'present' map type modifier does not exist for host address 0x{{0*}}[[#HOST_ADDR]] (0 bytes)
24*330d8983SJohannes Doerfert   // CHECK: omptarget error: Call to getTargetPointer returned null pointer ('present' map type modifier).
25*330d8983SJohannes Doerfert   // CHECK: omptarget error: Call to targetDataBegin failed, abort target.
26*330d8983SJohannes Doerfert   // CHECK: omptarget error: Failed to process data before launching the kernel.
27*330d8983SJohannes Doerfert   // CHECK: omptarget fatal error 1: failure of target construct while offloading is mandatory
28*330d8983SJohannes Doerfert #pragma omp target data map(alloc : arr[0 : 0])
29*330d8983SJohannes Doerfert #pragma omp target map(present, alloc : arr[0 : 0])
30*330d8983SJohannes Doerfert   ;
31*330d8983SJohannes Doerfert 
32*330d8983SJohannes Doerfert   // CHECK-NOT: arr is present
33*330d8983SJohannes Doerfert   fprintf(stderr, "arr is present\n");
34*330d8983SJohannes Doerfert 
35*330d8983SJohannes Doerfert   return 0;
36*330d8983SJohannes Doerfert }
37