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

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