1 | // RUN: %libomptarget-compilexx-run-and-check-aarch64-unknown-linux-gnu |
2 | // RUN: %libomptarget-compilexx-run-and-check-powerpc64-ibm-linux-gnu |
3 | // RUN: %libomptarget-compilexx-run-and-check-powerpc64le-ibm-linux-gnu |
4 | // RUN: %libomptarget-compilexx-run-and-check-x86_64-pc-linux-gnu |
5 | // RUN: %libomptarget-compilexx-run-and-check-nvptx64-nvidia-cuda |
6 | |
7 | #include <cstdio> |
8 | #include <cstdlib> |
9 | |
10 | typedef struct { |
11 | int a; |
12 | double *b; |
13 | } C1; |
14 | #pragma omp declare mapper(C1 s) map(to : s.a) map(from : s.b[0 : 2]) |
15 | |
16 | typedef struct { |
17 | int a; |
18 | double *b; |
19 | C1 c; |
20 | } C; |
21 | #pragma omp declare mapper(C s) map(to : s.a, s.c) map(from : s.b[0 : 2]) |
22 | |
23 | typedef struct { |
24 | int e; |
25 | C f; |
26 | int h; |
27 | } D; |
28 | |
29 | int main() { |
30 | constexpr int N = 10; |
31 | D s; |
32 | s.e = 111; |
33 | s.f.a = 222; |
34 | s.f.c.a = 777; |
35 | double x[2]; |
36 | double x1[2]; |
37 | x[1] = 20; |
38 | s.f.b = &x[0]; |
39 | s.f.c.b = &x1[0]; |
40 | s.h = N; |
41 | |
42 | printf(format: "%d %d %d %4.5f %d\n" , s.e, s.f.a, s.f.c.a, s.f.b[1], |
43 | s.f.b == &x[0] ? 1 : 0); |
44 | // CHECK: 111 222 777 20.00000 1 |
45 | |
46 | __intptr_t p = reinterpret_cast<__intptr_t>(&x[0]); |
47 | |
48 | #pragma omp target map(tofrom : s) firstprivate(p) |
49 | { |
50 | printf(format: "%d %d %d\n" , s.f.a, s.f.c.a, |
51 | s.f.b == reinterpret_cast<void *>(p) ? 1 : 0); |
52 | // CHECK: 222 777 0 |
53 | s.e = 333; |
54 | s.f.a = 444; |
55 | s.f.c.a = 555; |
56 | s.f.b[1] = 40; |
57 | } |
58 | |
59 | printf(format: "%d %d %d %4.5f %d\n" , s.e, s.f.a, s.f.c.a, s.f.b[1], |
60 | s.f.b == &x[0] ? 1 : 0); |
61 | // CHECK: 333 222 777 40.00000 1 |
62 | } |
63 | |