xref: /llvm-project/offload/test/mapping/lambda_by_value.cpp (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 // RUN: %libomptarget-compilexx-run-and-check-generic
2 
3 #include <stdint.h>
4 #include <stdio.h>
5 
6 // CHECK: before: [[V1:111]] [[V2:222]] [[PX:0x[^ ]+]] [[PY:0x[^ ]+]]
7 // CHECK: lambda: [[V1]] [[V2]] [[PX_TGT:0x[^ ]+]] 0x{{.*}}
8 // CHECK: tgt   : [[V2]] [[PX_TGT]] 1
9 // CHECK: out   : [[V2]] [[V2]] [[PX]] [[PY]]
10 
11 #pragma omp begin declare target
12 int a = -1, *c;
13 long b = -1;
14 const long *d;
15 int e = -1, *f, g = -1;
16 #pragma omp end declare target
17 
main()18 int main() {
19   int x[10];
20   long y[8];
21   x[1] = 111;
22   y[1] = 222;
23 
24   auto lambda = [&x, y]() {
25     a = x[1];
26     b = y[1];
27     c = &x[0];
28     d = &y[0];
29     printf("lambda: %d %ld %p %p\n", x[1], y[1], &x[0], &y[0]);
30     x[1] = y[1];
31   };
32   printf("before: %d %ld %p %p\n", x[1], y[1], &x[0], &y[0]);
33 
34   intptr_t xp = (intptr_t)&x[0];
35 #pragma omp target firstprivate(xp)
36   {
37     lambda();
38     e = x[1];
39     f = &x[0];
40     g = (&x[0] != (int *)xp);
41     printf("tgt   : %d %p %d\n", x[1], &x[0], (&x[0] != (int *)xp));
42   }
43 #pragma omp target update from(a, b, c, d, e, f, g)
44   printf("lambda: %d %ld %p %p\n", a, b, c, d);
45   printf("tgt   : %d %p %d\n", e, f, g);
46   printf("out   : %d %ld %p %p\n", x[1], y[1], &x[0], &y[0]);
47 
48   return 0;
49 }
50