1 | // RUN: %libomptarget-compilexx-generic -fopenmp-version=51 |
2 | // RUN: %libomptarget-run-generic 2>&1 \ |
3 | // RUN: | %fcheck-generic |
4 | |
5 | // FIXME: This is currently broken on all GPU targets |
6 | // UNSUPPORTED: amdgcn-amd-amdhsa |
7 | // UNSUPPORTED: nvptx64-nvidia-cuda |
8 | // UNSUPPORTED: nvptx64-nvidia-cuda-LTO |
9 | |
10 | #include <stdio.h> |
11 | #include <stdlib.h> |
12 | |
13 | void foo(int **t1d) { |
14 | int ***t2d = &t1d; |
15 | int ****t3d = &t2d; |
16 | *t1d = (int *)malloc(size: 3 * sizeof(int)); |
17 | int j, a = 0, b = 0; |
18 | |
19 | for (j = 0; j < 3; j++) |
20 | (*t1d)[j] = 0; |
21 | #pragma omp target map(tofrom : (*t1d)[0 : 3]) |
22 | { (*t1d)[1] = 1; } |
23 | // CHECK: 1 |
24 | printf(format: "%d\n" , (*t1d)[1]); |
25 | #pragma omp target map(tofrom : (**t2d)[0 : 3]) |
26 | { (**t2d)[1] = 2; } |
27 | // CHECK: 2 |
28 | printf(format: "%d\n" , (**t2d)[1]); |
29 | #pragma omp target map(tofrom : (***t3d)[0 : 3]) |
30 | { (***t3d)[1] = 3; } |
31 | // CHECK: 3 |
32 | printf(format: "%d\n" , (***t3d)[1]); |
33 | #pragma omp target map(tofrom : (**t1d)) |
34 | { (*t1d)[0] = 4; } |
35 | // CHECK: 4 |
36 | printf(format: "%d\n" , (*t1d)[0]); |
37 | #pragma omp target map(tofrom : (*(*(t1d + a) + b))) |
38 | { *(*(t1d + a) + b) = 5; } |
39 | // CHECK: 5 |
40 | printf(format: "%d\n" , *(*(t1d + a) + b)); |
41 | } |
42 | |
43 | typedef int(T)[3]; |
44 | void bar() { |
45 | T **a; |
46 | int b[2][3]; |
47 | int(*p)[3] = b; |
48 | a = &p; |
49 | for (int i = 0; i < 3; i++) { |
50 | (**a)[1] = i; |
51 | } |
52 | #pragma omp target map((**a)[ : 3]) |
53 | { |
54 | (**a)[1] = 6; |
55 | // CHECK: 6 |
56 | printf(format: "%d\n" , (**a)[1]); |
57 | } |
58 | } |
59 | |
60 | struct SSA { |
61 | int i; |
62 | SSA *sa; |
63 | SSA() { |
64 | i = 1; |
65 | sa = this; |
66 | } |
67 | }; |
68 | |
69 | void zoo(int **f, SSA *sa) { |
70 | int *t = *f; |
71 | f = (int **)malloc(size: sa->i * 4 * sizeof(int)); |
72 | t = (int *)malloc(size: sa->i * sizeof(int)); |
73 | *(f + sa->i + 1) = t; |
74 | *(sa->sa->i + *(f + sa->i + 1)) = 4; |
75 | printf(format: "%d\n" , *(sa->sa->i + *(1 + sa->i + f))); |
76 | #pragma omp target map(sa, *(sa->sa->i + *(1 + sa->i + f))) |
77 | { *(sa->sa->i + *(1 + sa->i + f)) = 7; } |
78 | // CHECK: 7 |
79 | printf(format: "%d\n" , *(sa->sa->i + *(1 + sa->i + f))); |
80 | } |
81 | |
82 | void xoo() { |
83 | int *x = 0; |
84 | SSA *sa = new SSA(); |
85 | zoo(f: &x, sa); |
86 | } |
87 | |
88 | void yoo(int **x) { |
89 | *x = (int *)malloc(size: 2 * sizeof(int)); |
90 | #pragma omp target map(**x) |
91 | { |
92 | **x = 8; |
93 | // CHECK: 8 |
94 | printf(format: "%d\n" , **x); |
95 | } |
96 | #pragma omp target map(*(*x + 1)) |
97 | { |
98 | *(*x + 1) = 9; |
99 | // CHECK: 9 |
100 | printf(format: "%d\n" , *(*x + 1)); |
101 | } |
102 | } |
103 | |
104 | int main() { |
105 | int *data = 0; |
106 | foo(t1d: &data); |
107 | bar(); |
108 | xoo(); |
109 | yoo(x: &data); |
110 | } |
111 | |