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

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