xref: /llvm-project/offload/test/offloading/bug53727.cpp (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 // RUN: %libomptarget-compilexx-and-run-generic
2 // RUN: %libomptarget-compileoptxx-and-run-generic
3 
4 #include <cassert>
5 #include <iostream>
6 
7 constexpr const int N = 10;
8 
9 struct T {
10   int a;
11   int *p;
12 };
13 
14 struct S {
15   int b;
16   T t;
17 };
18 
main(int argc,char * argv[])19 int main(int argc, char *argv[]) {
20   S s;
21   s.t.p = new int[N];
22   for (int i = 0; i < N; ++i) {
23     s.t.p[i] = i;
24   }
25 
26 #pragma omp target enter data map(to : s, s.t.p[ : N])
27 
28 #pragma omp target
29   {
30     for (int i = 0; i < N; ++i) {
31       s.t.p[i] += i;
32     }
33   }
34 
35 #pragma omp target update from(s.t.p[ : N])
36 
37   for (int i = 0; i < N; ++i) {
38     assert(s.t.p[i] == 2 * i);
39     s.t.p[i] += i;
40   }
41 
42 #pragma omp target update to(s.t.p[ : N])
43 
44 #pragma omp target
45   {
46     for (int i = 0; i < N; ++i) {
47       s.t.p[i] += i;
48     }
49   }
50 
51 #pragma omp target exit data map(from : s, s.t.p[ : N])
52 
53   for (int i = 0; i < N; ++i) {
54     assert(s.t.p[i] == 4 * i);
55   }
56 
57   return 0;
58 }
59