Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / libomptarget / test / mapping / target_derefence_array_pointrs.cpp
blob7d4bc9ea2247892a235c3dade0ef2abeb044d529
1 // RUN: %libomptarget-compilexx-generic -fopenmp-version=51
2 // RUN: %libomptarget-run-generic 2>&1 \
3 // RUN: | %fcheck-generic
5 // UNSUPPORTED: amdgcn-amd-amdhsa
7 #include <stdio.h>
8 #include <stdlib.h>
10 void foo(int **t1d) {
11 int ***t2d = &t1d;
12 int ****t3d = &t2d;
13 *t1d = (int *)malloc(3 * sizeof(int));
14 int j, a = 0, b = 0;
16 for (j = 0; j < 3; j++)
17 (*t1d)[j] = 0;
18 #pragma omp target map(tofrom : (*t1d)[0 : 3])
19 { (*t1d)[1] = 1; }
20 // CHECK: 1
21 printf("%d\n", (*t1d)[1]);
22 #pragma omp target map(tofrom : (**t2d)[0 : 3])
23 { (**t2d)[1] = 2; }
24 // CHECK: 2
25 printf("%d\n", (**t2d)[1]);
26 #pragma omp target map(tofrom : (***t3d)[0 : 3])
27 { (***t3d)[1] = 3; }
28 // CHECK: 3
29 printf("%d\n", (***t3d)[1]);
30 #pragma omp target map(tofrom : (**t1d))
31 { (*t1d)[0] = 4; }
32 // CHECK: 4
33 printf("%d\n", (*t1d)[0]);
34 #pragma omp target map(tofrom : (*(*(t1d + a) + b)))
35 { *(*(t1d + a) + b) = 5; }
36 // CHECK: 5
37 printf("%d\n", *(*(t1d + a) + b));
40 typedef int(T)[3];
41 void bar() {
42 T **a;
43 int b[2][3];
44 int(*p)[3] = b;
45 a = &p;
46 for (int i = 0; i < 3; i++) {
47 (**a)[1] = i;
49 #pragma omp target map((**a)[ : 3])
51 (**a)[1] = 6;
52 // CHECK: 6
53 printf("%d\n", (**a)[1]);
57 struct SSA {
58 int i;
59 SSA *sa;
60 SSA() {
61 i = 1;
62 sa = this;
66 void zoo(int **f, SSA *sa) {
67 int *t = *f;
68 f = (int **)malloc(sa->i * 4 * sizeof(int));
69 t = (int *)malloc(sa->i * sizeof(int));
70 *(f + sa->i + 1) = t;
71 *(sa->sa->i + *(f + sa->i + 1)) = 4;
72 printf("%d\n", *(sa->sa->i + *(1 + sa->i + f)));
73 #pragma omp target map(sa, *(sa->sa->i + *(1 + sa->i + f)))
74 { *(sa->sa->i + *(1 + sa->i + f)) = 7; }
75 // CHECK: 7
76 printf("%d\n", *(sa->sa->i + *(1 + sa->i + f)));
79 void xoo() {
80 int *x = 0;
81 SSA *sa = new SSA();
82 zoo(&x, sa);
85 void yoo(int **x) {
86 *x = (int *)malloc(2 * sizeof(int));
87 #pragma omp target map(**x)
89 **x = 8;
90 // CHECK: 8
91 printf("%d\n", **x);
93 #pragma omp target map(*(*x + 1))
95 *(*x + 1) = 9;
96 // CHECK: 9
97 printf("%d\n", *(*x + 1));
101 int main() {
102 int *data = 0;
103 foo(&data);
104 bar();
105 xoo();
106 yoo(&data);