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