llvm-project
110 строк · 2.2 Кб
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
13void foo(int **t1d) {
14int ***t2d = &t1d;
15int ****t3d = &t2d;
16*t1d = (int *)malloc(3 * sizeof(int));
17int j, a = 0, b = 0;
18
19for (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
24printf("%d\n", (*t1d)[1]);
25#pragma omp target map(tofrom : (**t2d)[0 : 3])
26{ (**t2d)[1] = 2; }
27// CHECK: 2
28printf("%d\n", (**t2d)[1]);
29#pragma omp target map(tofrom : (***t3d)[0 : 3])
30{ (***t3d)[1] = 3; }
31// CHECK: 3
32printf("%d\n", (***t3d)[1]);
33#pragma omp target map(tofrom : (**t1d))
34{ (*t1d)[0] = 4; }
35// CHECK: 4
36printf("%d\n", (*t1d)[0]);
37#pragma omp target map(tofrom : (*(*(t1d + a) + b)))
38{ *(*(t1d + a) + b) = 5; }
39// CHECK: 5
40printf("%d\n", *(*(t1d + a) + b));
41}
42
43typedef int(T)[3];
44void bar() {
45T **a;
46int b[2][3];
47int(*p)[3] = b;
48a = &p;
49for (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
56printf("%d\n", (**a)[1]);
57}
58}
59
60struct SSA {
61int i;
62SSA *sa;
63SSA() {
64i = 1;
65sa = this;
66}
67};
68
69void zoo(int **f, SSA *sa) {
70int *t = *f;
71f = (int **)malloc(sa->i * 4 * sizeof(int));
72t = (int *)malloc(sa->i * sizeof(int));
73*(f + sa->i + 1) = t;
74*(sa->sa->i + *(f + sa->i + 1)) = 4;
75printf("%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
79printf("%d\n", *(sa->sa->i + *(1 + sa->i + f)));
80}
81
82void xoo() {
83int *x = 0;
84SSA *sa = new SSA();
85zoo(&x, sa);
86}
87
88void yoo(int **x) {
89*x = (int *)malloc(2 * sizeof(int));
90#pragma omp target map(**x)
91{
92**x = 8;
93// CHECK: 8
94printf("%d\n", **x);
95}
96#pragma omp target map(*(*x + 1))
97{
98*(*x + 1) = 9;
99// CHECK: 9
100printf("%d\n", *(*x + 1));
101}
102}
103
104int main() {
105int *data = 0;
106foo(&data);
107bar();
108xoo();
109yoo(&data);
110}
111