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
10typedef 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
16typedef 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
23typedef struct {
24 int e;
25 C f;
26 int h;
27} D;
28
29int 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 D *sp = &s;
43
44 printf(format: "%d %d %d %4.5f %d\n", sp[0].e, sp[0].f.a, sp[0].f.c.a, sp[0].f.b[1],
45 sp[0].f.b == &x[0] ? 1 : 0);
46 // CHECK: 111 222 777 20.00000 1
47
48 __intptr_t p = reinterpret_cast<__intptr_t>(&x[0]);
49#pragma omp target map(tofrom : sp[0]) firstprivate(p)
50 {
51 printf(format: "%d %d %d\n", sp[0].f.a, sp[0].f.c.a,
52 sp[0].f.b == reinterpret_cast<void *>(p) ? 1 : 0);
53 // CHECK: 222 777 0
54 sp[0].e = 333;
55 sp[0].f.a = 444;
56 sp[0].f.c.a = 555;
57 sp[0].f.b[1] = 40;
58 }
59 printf(format: "%d %d %d %4.5f %d\n", sp[0].e, sp[0].f.a, sp[0].f.c.a, sp[0].f.b[1],
60 sp[0].f.b == &x[0] ? 1 : 0);
61 // CHECK: 333 222 777 40.00000 1
62}
63

source code of offload/test/mapping/declare_mapper_nested_default_mappers_ptr_subscript.cpp