[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / target_is_device_ptr_messages.cpp
blob7137f5deff19d39110205a16d7b993f8dfef6e04
1 // RUN: %clang_cc1 -std=c++11 -verify=expected,omp45 -fopenmp -fopenmp-version=45 -ferror-limit 200 %s -Wuninitialized
2 // RUN: %clang_cc1 -std=c++11 -verify=expected,omp50 -fopenmp -ferror-limit 200 %s -Wuninitialized
4 // RUN: %clang_cc1 -std=c++11 -verify=expected,omp45 -fopenmp-simd -fopenmp-version=45 -ferror-limit 200 %s -Wuninitialized
5 // RUN: %clang_cc1 -std=c++11 -verify=expected,omp50 -fopenmp-simd -ferror-limit 200 %s -Wuninitialized
6 struct ST {
7 int *a;
8 };
9 typedef int arr[10];
10 typedef ST STarr[10];
11 struct SA {
12 const int d = 5;
13 const int da[5] = { 0 };
14 ST e;
15 ST g[10];
16 STarr &rg = g;
17 int i;
18 int &j = i;
19 int *k = &j;
20 int *&z = k;
21 int aa[10];
22 arr &raa = aa;
23 void func(int arg) {
24 #pragma omp target is_device_ptr // expected-error {{expected '(' after 'is_device_ptr'}}
26 #pragma omp target is_device_ptr( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}}
28 #pragma omp target is_device_ptr() // expected-error {{expected expression}}
30 #pragma omp target is_device_ptr(alloc) // expected-error {{use of undeclared identifier 'alloc'}}
32 #pragma omp target is_device_ptr(arg // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
34 #pragma omp target is_device_ptr(i) // expected-error {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
36 #pragma omp target is_device_ptr(j) // expected-error {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
38 #pragma omp target is_device_ptr(k) // OK
40 #pragma omp target is_device_ptr(z) // OK
42 #pragma omp target is_device_ptr(aa) // OK
44 #pragma omp target is_device_ptr(raa) // OK
46 #pragma omp target is_device_ptr(e) // expected-error{{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
48 #pragma omp target is_device_ptr(g) // OK
50 #pragma omp target is_device_ptr(rg) // OK
52 #pragma omp target is_device_ptr(k,i,j) // expected-error2 {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
54 #pragma omp target is_device_ptr(d) // expected-error{{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
56 #pragma omp target is_device_ptr(da) // OK
58 return;
61 struct SB {
62 unsigned A;
63 unsigned B;
64 float Arr[100];
65 float *Ptr;
66 float *foo() {
67 return &Arr[0];
71 struct SC {
72 unsigned A : 2;
73 unsigned B : 3;
74 unsigned C;
75 unsigned D;
76 float Arr[100];
77 SB S;
78 SB ArrS[100];
79 SB *PtrS;
80 SB *&RPtrS;
81 float *Ptr;
83 SC(SB *&_RPtrS) : RPtrS(_RPtrS) {}
86 union SD {
87 unsigned A;
88 float B;
91 struct S1;
92 extern S1 a;
93 class S2 {
94 mutable int a;
95 public:
96 S2():a(0) { }
97 S2(S2 &s2):a(s2.a) { }
98 static float S2s;
99 static const float S2sc;
101 const float S2::S2sc = 0;
102 const S2 b;
103 const S2 ba[5];
104 class S3 {
105 int a;
106 public:
107 S3():a(0) { }
108 S3(S3 &s3):a(s3.a) { }
110 const S3 c;
111 const S3 ca[5];
112 extern const int f;
113 class S4 {
114 int a;
115 S4();
116 S4(const S4 &s4);
117 public:
118 S4(int v):a(v) { }
120 class S5 {
121 int a;
122 S5():a(0) {}
123 S5(const S5 &s5):a(s5.a) { }
124 public:
125 S5(int v):a(v) { }
128 S3 h;
129 #pragma omp threadprivate(h)
131 typedef struct {
132 int a;
133 } S6;
135 template <typename T, int I>
136 T tmain(T argc) {
137 const T d = 5;
138 const T da[5] = { 0 };
139 S4 e(4);
140 S5 g(5);
141 S6 h[10];
142 auto &rh = h;
143 T i;
144 T &j = i;
145 T *k = &j;
146 T *&z = k;
147 T aa[10];
148 auto &raa = aa;
149 S6 *ps;
150 #pragma omp target is_device_ptr // expected-error {{expected '(' after 'is_device_ptr'}}
152 #pragma omp target is_device_ptr( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}}
154 #pragma omp target is_device_ptr() // expected-error {{expected expression}}
156 #pragma omp target is_device_ptr(alloc) // expected-error {{use of undeclared identifier 'alloc'}}
158 #pragma omp target is_device_ptr(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error{{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
160 #pragma omp target is_device_ptr(i) // expected-error {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
162 #pragma omp target is_device_ptr(j) // expected-error {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
164 #pragma omp target is_device_ptr(k) // OK
166 #pragma omp target is_device_ptr(z) // OK
168 #pragma omp target is_device_ptr(aa) // OK
170 #pragma omp target is_device_ptr(raa) // OK
172 #pragma omp target is_device_ptr(e) // expected-error{{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
174 #pragma omp target is_device_ptr(g) // expected-error{{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
176 #pragma omp target is_device_ptr(h) // OK
178 #pragma omp target is_device_ptr(rh) // OK
180 #pragma omp target is_device_ptr(k,i,j) // expected-error2 {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
182 #pragma omp target is_device_ptr(d) // expected-error{{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
184 #pragma omp target is_device_ptr(da) // OK
186 #pragma omp target map(ps) is_device_ptr(ps) // expected-error{{variable already marked as mapped in current construct}} expected-note{{used here}}
188 #pragma omp target is_device_ptr(ps) map(ps) // expected-error{{variable already marked as mapped in current construct}} expected-note{{used here}}
190 #pragma omp target map(ps->a) is_device_ptr(ps) // expected-error{{variable already marked as mapped in current construct}} expected-note{{used here}}
192 #pragma omp target is_device_ptr(ps) map(ps->a) // expected-error{{pointer cannot be mapped along with a section derived from itself}} expected-note{{used here}}
194 #pragma omp target is_device_ptr(ps) firstprivate(ps) // expected-error{{firstprivate variable cannot be in a is_device_ptr clause in '#pragma omp target' directive}}
196 #pragma omp target firstprivate(ps) is_device_ptr(ps) // expected-error{{firstprivate variable cannot be in a is_device_ptr clause in '#pragma omp target' directive}} expected-note{{defined as firstprivate}}
198 #pragma omp target is_device_ptr(ps) private(ps) // expected-error{{private variable cannot be in a is_device_ptr clause in '#pragma omp target' directive}}
200 #pragma omp target private(ps) is_device_ptr(ps) // expected-error{{private variable cannot be in a is_device_ptr clause in '#pragma omp target' directive}} expected-note{{defined as private}}
202 return 0;
205 int main(int argc, char **argv) {
206 const int d = 5;
207 const int da[5] = { 0 };
208 S4 e(4);
209 S5 g(5);
210 S6 h[10];
211 auto &rh = h;
212 int i;
213 int &j = i;
214 int *k = &j;
215 int *&z = k;
216 int aa[10];
217 auto &raa = aa;
218 S6 *ps;
219 #pragma omp target is_device_ptr // expected-error {{expected '(' after 'is_device_ptr'}}
221 #pragma omp target is_device_ptr( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}}
223 #pragma omp target is_device_ptr() // expected-error {{expected expression}}
225 #pragma omp target is_device_ptr(alloc) // expected-error {{use of undeclared identifier 'alloc'}}
227 #pragma omp target is_device_ptr(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
229 #pragma omp target is_device_ptr(i) // expected-error {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
231 #pragma omp target is_device_ptr(j) // expected-error {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
233 #pragma omp target is_device_ptr(k) // OK
235 #pragma omp target is_device_ptr(z) // OK
237 #pragma omp target is_device_ptr(aa) // OK
239 #pragma omp target is_device_ptr(raa) // OK
241 #pragma omp target is_device_ptr(e) // expected-error{{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
243 #pragma omp target is_device_ptr(g) // expected-error{{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
245 #pragma omp target is_device_ptr(h) // OK
247 #pragma omp target is_device_ptr(rh) // OK
249 #pragma omp target is_device_ptr(k,i,j) // expected-error2 {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
251 #pragma omp target is_device_ptr(d) // expected-error{{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
253 #pragma omp target is_device_ptr(da) // OK
255 #pragma omp target map(ps) is_device_ptr(ps) // expected-error{{variable already marked as mapped in current construct}} expected-note{{used here}}
257 #pragma omp target is_device_ptr(ps) map(ps) // expected-error{{variable already marked as mapped in current construct}} expected-note{{used here}}
259 #pragma omp target map(ps->a) is_device_ptr(ps) // expected-error{{variable already marked as mapped in current construct}} expected-note{{used here}}
261 #pragma omp target is_device_ptr(ps) map(ps->a) // expected-error{{pointer cannot be mapped along with a section derived from itself}} expected-note{{used here}}
263 #pragma omp target is_device_ptr(ps) firstprivate(ps) // expected-error{{firstprivate variable cannot be in a is_device_ptr clause in '#pragma omp target' directive}}
265 #pragma omp target firstprivate(ps) is_device_ptr(ps) // expected-error{{firstprivate variable cannot be in a is_device_ptr clause in '#pragma omp target' directive}} expected-note{{defined as firstprivate}}
267 #pragma omp target is_device_ptr(ps) private(ps) // expected-error{{private variable cannot be in a is_device_ptr clause in '#pragma omp target' directive}}
269 #pragma omp target private(ps) is_device_ptr(ps) // expected-error{{private variable cannot be in a is_device_ptr clause in '#pragma omp target' directive}} expected-note{{defined as private}}
271 return tmain<int, 3>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}}