xref: /llvm-project/offload/test/mapping/device_ptr_update.c (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 // RUN: %libomptarget-compile-generic
2 // RUN: env LIBOMPTARGET_DEBUG=1 %libomptarget-run-generic 2>&1 \
3 // RUN: | %fcheck-generic -check-prefix=DEBUG -check-prefix=CHECK
4 // REQUIRES: libomptarget-debug
5 
6 #include <stdio.h>
7 
8 struct S {
9   int *p;
10 };
11 
main(void)12 int main(void) {
13   int A[10];
14   struct S s1;
15 
16   s1.p = A;
17 
18 // DEBUG: Update pointer ([[DEV_PTR:0x[^ ]+]]) -> {{\[}}[[DEV_OBJ_A:0x[^ ]+]]{{\]}}
19 #pragma omp target enter data map(alloc : s1.p[0 : 10])
20 
21 // DEBUG-NOT: Update pointer ([[DEV_PTR]]) -> {{\[}}[[DEV_OBJ_A]]{{\]}}
22 #pragma omp target map(alloc : s1.p[0 : 10])
23   {
24     for (int i = 0; i < 10; ++i)
25       s1.p[i] = i;
26   }
27 
28 #pragma omp target exit data map(from : s1.p[0 : 10])
29 
30   int fail_A = 0;
31   for (int i = 0; i < 10; ++i) {
32     if (A[i] != i) {
33       fail_A = 1;
34       break;
35     }
36   }
37 
38   // CHECK-NOT: Test A failed
39   if (fail_A) {
40     printf("Test A failed\n");
41   }
42 
43   return fail_A;
44 }
45