xref: /llvm-project/offload/test/mapping/data_member_ref.cpp (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 // RUN: %libomptarget-compilexx-run-and-check-generic
2 
3 #include <stdio.h>
4 
5 struct View {
6   int Data;
7 };
8 
9 struct ViewPtr {
10   int *Data;
11 };
12 
13 template <typename T> struct Foo {
FooFoo14   Foo(T &V) : VRef(V) {}
15   T &VRef;
16 };
17 
main()18 int main() {
19   View V;
20   V.Data = 123456;
21   Foo<View> Bar(V);
22   ViewPtr V1;
23   int Data = 123456;
24   V1.Data = &Data;
25   Foo<ViewPtr> Baz(V1);
26   int D1, D2;
27 
28   // CHECK: Host 123456.
29   printf("Host %d.\n", Bar.VRef.Data);
30 #pragma omp target map(Bar.VRef) map(from : D1, D2)
31   {
32     // CHECK: Device 123456.
33     D1 = Bar.VRef.Data;
34     printf("Device %d.\n", D1);
35     V.Data = 654321;
36     // CHECK: Device 654321.
37     D2 = Bar.VRef.Data;
38     printf("Device %d.\n", D2);
39   }
40   printf("Device %d.\n", D1);
41   printf("Device %d.\n", D2);
42   // CHECK: Host 654321 654321.
43   printf("Host %d %d.\n", Bar.VRef.Data, V.Data);
44   V.Data = 123456;
45   // CHECK: Host 123456.
46   printf("Host %d.\n", Bar.VRef.Data);
47 #pragma omp target map(Bar) map(Bar.VRef) map(from : D1, D2)
48   {
49     // CHECK: Device 123456.
50     D1 = Bar.VRef.Data;
51     printf("Device %d.\n", D1);
52     V.Data = 654321;
53     // CHECK: Device 654321.
54     D2 = Bar.VRef.Data;
55     printf("Device %d.\n", D2);
56   }
57   printf("Device %d.\n", D1);
58   printf("Device %d.\n", D2);
59   // CHECK: Host 654321 654321.
60   printf("Host %d %d.\n", Bar.VRef.Data, V.Data);
61   // CHECK: Host 123456.
62   printf("Host %d.\n", *Baz.VRef.Data);
63 #pragma omp target map(*Baz.VRef.Data) map(from : D1, D2)
64   {
65     // CHECK: Device 123456.
66     D1 = *Baz.VRef.Data;
67     printf("Device %d.\n", D1);
68     *V1.Data = 654321;
69     // CHECK: Device 654321.
70     D2 = *Baz.VRef.Data;
71     printf("Device %d.\n", D2);
72   }
73   printf("Device %d.\n", D1);
74   printf("Device %d.\n", D2);
75   // CHECK: Host 654321 654321 654321.
76   printf("Host %d %d %d.\n", *Baz.VRef.Data, *V1.Data, Data);
77   return 0;
78 }
79