[HLSL] Implement RWBuffer::operator[] via __builtin_hlsl_resource_getpointer (#117017)
[llvm-project.git] / offload / test / mapping / declare_mapper_nested_default_mappers_var.cpp
blob817e9684a8a2e6b84fb06bd8ad4ed111ba10ea8a
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-unknown-linux-gnu
5 // RUN: %libomptarget-compilexx-run-and-check-nvptx64-nvidia-cuda
7 #include <cstdio>
8 #include <cstdlib>
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])
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])
23 typedef struct {
24 int e;
25 C f;
26 int h;
27 } D;
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;
42 printf("%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
46 __intptr_t p = reinterpret_cast<__intptr_t>(&x[0]);
48 #pragma omp target map(tofrom : s) firstprivate(p)
50 printf("%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;
59 printf("%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