Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / mapping / target_derefence_array_pointrs.cpp
bloba6dd4069a8f588d7bcdab7bedf812366dd46abca
1 // RUN: %libomptarget-compilexx-generic -fopenmp-version=51
2 // RUN: %libomptarget-run-generic 2>&1 \
3 // RUN: | %fcheck-generic
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
10 #include <stdio.h>
11 #include <stdlib.h>
13 void foo(int **t1d) {
14 int ***t2d = &t1d;
15 int ****t3d = &t2d;
16 *t1d = (int *)malloc(3 * sizeof(int));
17 int j, a = 0, b = 0;
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("%d\n", (*t1d)[1]);
25 #pragma omp target map(tofrom : (**t2d)[0 : 3])
26 { (**t2d)[1] = 2; }
27 // CHECK: 2
28 printf("%d\n", (**t2d)[1]);
29 #pragma omp target map(tofrom : (***t3d)[0 : 3])
30 { (***t3d)[1] = 3; }
31 // CHECK: 3
32 printf("%d\n", (***t3d)[1]);
33 #pragma omp target map(tofrom : (**t1d))
34 { (*t1d)[0] = 4; }
35 // CHECK: 4
36 printf("%d\n", (*t1d)[0]);
37 #pragma omp target map(tofrom : (*(*(t1d + a) + b)))
38 { *(*(t1d + a) + b) = 5; }
39 // CHECK: 5
40 printf("%d\n", *(*(t1d + a) + b));
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;
52 #pragma omp target map((**a)[ : 3])
54 (**a)[1] = 6;
55 // CHECK: 6
56 printf("%d\n", (**a)[1]);
60 struct SSA {
61 int i;
62 SSA *sa;
63 SSA() {
64 i = 1;
65 sa = this;
69 void zoo(int **f, SSA *sa) {
70 int *t = *f;
71 f = (int **)malloc(sa->i * 4 * sizeof(int));
72 t = (int *)malloc(sa->i * sizeof(int));
73 *(f + sa->i + 1) = t;
74 *(sa->sa->i + *(f + sa->i + 1)) = 4;
75 printf("%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("%d\n", *(sa->sa->i + *(1 + sa->i + f)));
82 void xoo() {
83 int *x = 0;
84 SSA *sa = new SSA();
85 zoo(&x, sa);
88 void yoo(int **x) {
89 *x = (int *)malloc(2 * sizeof(int));
90 #pragma omp target map(**x)
92 **x = 8;
93 // CHECK: 8
94 printf("%d\n", **x);
96 #pragma omp target map(*(*x + 1))
98 *(*x + 1) = 9;
99 // CHECK: 9
100 printf("%d\n", *(*x + 1));
104 int main() {
105 int *data = 0;
106 foo(&data);
107 bar();
108 xoo();
109 yoo(&data);