Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / mapping / declare_mapper_nested_mappers.cpp
bloba9e3f05e0f5fd030ae10b0a5d29a46e17107ba01
1 // RUN: %libomptarget-compilexx-run-and-check-generic
3 #include <cstdio>
4 #include <cstdlib>
6 typedef struct {
7 int a;
8 double *b;
9 } C;
10 #pragma omp declare mapper(id1 : C s) map(to : s.a) map(from : s.b[0 : 2])
12 typedef struct {
13 int e;
14 C f;
15 int h;
16 short *g;
17 } D;
18 #pragma omp declare mapper(default : D r) map(from : r.e) \
19 map(mapper(id1), tofrom : r.f) map(tofrom : r.g[0 : r.h])
21 int main() {
22 constexpr int N = 10;
23 D s;
24 s.e = 111;
25 s.f.a = 222;
26 double x[2];
27 x[1] = 20;
28 short y[N];
29 y[1] = 30;
30 s.f.b = &x[0];
31 s.g = &y[0];
32 s.h = N;
34 D *sp = &s;
35 D **spp = &sp;
37 printf("%d %d %4.5f %d %d %d\n", spp[0][0].e, spp[0][0].f.a, spp[0][0].f.b[1],
38 spp[0][0].f.b == &x[0] ? 1 : 0, spp[0][0].g[1],
39 spp[0][0].g == &y[0] ? 1 : 0);
40 // CHECK: 111 222 20.00000 1 30 1
42 int spp00fa = -1, spp00fb_r = -1, spp00fg1 = -1, spp00fg_r = -1;
43 __intptr_t p = reinterpret_cast<__intptr_t>(&x[0]),
44 p1 = reinterpret_cast<__intptr_t>(&y[0]);
45 #pragma omp target map(tofrom : spp[0][0]) firstprivate(p, p1) \
46 map(from: spp00fa, spp00fb_r, spp00fg1, spp00fg_r)
48 spp00fa = spp[0][0].f.a;
49 spp00fb_r = spp[0][0].f.b == reinterpret_cast<void *>(p) ? 1 : 0;
50 spp00fg1 = spp[0][0].g[1];
51 spp00fg_r = spp[0][0].g == reinterpret_cast<void *>(p1) ? 1 : 0;
52 printf("%d %d %d %d\n", spp00fa, spp00fb_r, spp00fg1, spp00fg_r);
53 // XCHECK: 222 0 30 0
54 spp[0][0].e = 333;
55 spp[0][0].f.a = 444;
56 spp[0][0].f.b[1] = 40;
57 spp[0][0].g[1] = 50;
59 printf("%d %d %d %d\n", spp00fa, spp00fb_r, spp00fg1, spp00fg_r);
60 // CHECK: 222 0 30 0
61 printf("%d %d %4.5f %d %d %d\n", spp[0][0].e, spp[0][0].f.a, spp[0][0].f.b[1],
62 spp[0][0].f.b == &x[0] ? 1 : 0, spp[0][0].g[1],
63 spp[0][0].g == &y[0] ? 1 : 0);
64 // CHECK: 333 222 40.00000 1 50 1