blob: 73ab06fcf408822df2d991e92dd16fcb17811433 [file] [log] [blame]
Alexey Bataeva9148882019-07-08 15:45:24 +00001// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
Kelvin Li787f3fc2016-07-06 04:45:38 +00002
Alexey Bataeva9148882019-07-08 15:45:24 +00003// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00004
Alexey Bataeve04483e2019-03-27 14:14:31 +00005extern int omp_default_mem_alloc;
Alexey Bataev195ae902019-08-08 13:42:45 +00006
7void xxx(int argc) {
8 int i;
9#pragma omp distribute simd linear(i)
10 for (i = 0; i < 10; ++i)
11 ;
12}
13
Kelvin Li787f3fc2016-07-06 04:45:38 +000014namespace X {
15 int x;
16};
17
18struct B {
19 static int ib; // expected-note {{'B::ib' declared here}}
20 static int bfoo() { return 8; }
21};
22
23int bfoo() { return 4; }
24
25int z;
26const int C1 = 1;
27const int C2 = 2;
28void test_linear_colons()
29{
30 int B = 0;
31
Alexey Bataev2b86f212017-11-29 21:31:48 +000032// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000033#pragma omp target
34#pragma omp teams
35#pragma omp distribute simd linear(B:bfoo())
36 for (int i = 0; i < 10; ++i) ;
37
Alexey Bataev2b86f212017-11-29 21:31:48 +000038// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000039#pragma omp target
40#pragma omp teams
41#pragma omp distribute simd linear(B::ib:B:bfoo()) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'}}
42 for (int i = 0; i < 10; ++i) ;
43
Alexey Bataev2b86f212017-11-29 21:31:48 +000044// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000045#pragma omp target
46#pragma omp teams
47#pragma omp distribute simd linear(B:ib) // expected-error {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
48 for (int i = 0; i < 10; ++i) ;
49
Alexey Bataev2b86f212017-11-29 21:31:48 +000050// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000051#pragma omp target
52#pragma omp teams
53#pragma omp distribute simd linear(z:B:ib) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}}
54 for (int i = 0; i < 10; ++i) ;
55
Alexey Bataev2b86f212017-11-29 21:31:48 +000056// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000057#pragma omp target
58#pragma omp teams
59#pragma omp distribute simd linear(B:B::bfoo())
60 for (int i = 0; i < 10; ++i) ;
61
Alexey Bataev2b86f212017-11-29 21:31:48 +000062// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000063#pragma omp target
64#pragma omp teams
65#pragma omp distribute simd linear(X::x : ::z)
66 for (int i = 0; i < 10; ++i) ;
67
Alexey Bataev2b86f212017-11-29 21:31:48 +000068// expected-error@+3 3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000069#pragma omp target
70#pragma omp teams
71#pragma omp distribute simd linear(B,::z, X::x)
72 for (int i = 0; i < 10; ++i) ;
73
Alexey Bataev2b86f212017-11-29 21:31:48 +000074// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000075#pragma omp target
76#pragma omp teams
77#pragma omp distribute simd linear(::z)
78 for (int i = 0; i < 10; ++i) ;
79
80#pragma omp target
81#pragma omp teams
82#pragma omp distribute simd linear(B::bfoo()) // expected-error {{expected variable name}}
83 for (int i = 0; i < 10; ++i) ;
84
Alexey Bataev2b86f212017-11-29 21:31:48 +000085// expected-error@+3 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000086#pragma omp target
87#pragma omp teams
88#pragma omp distribute simd linear(B::ib,B:C1+C2)
89 for (int i = 0; i < 10; ++i) ;
90}
91
92template<int L, class T, class N> T test_template(T* arr, N num) {
93 N i;
94 T sum = (T)0;
95 T ind2 = - num * L; // expected-note {{'ind2' defined here}}
96
97#pragma omp target
98#pragma omp teams
99#pragma omp distribute simd linear(ind2:L) // expected-error {{argument of a linear clause should be of integral or pointer type}}
100 for (i = 0; i < num; ++i) {
101 T cur = arr[(int)ind2];
102 ind2 += L;
103 sum += cur;
104 }
105 return T();
106}
107
108template<int LEN> int test_warn() {
109 int ind2 = 0;
110 #pragma omp target
111 #pragma omp teams
112 #pragma omp parallel for simd linear(ind2:LEN) // expected-warning {{zero linear step (ind2 should probably be const)}}
113 for (int i = 0; i < 100; i++) {
114 ind2 += LEN;
115 }
116 return ind2;
117}
118
119struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
120extern S1 a;
121class S2 {
122 mutable int a;
123public:
124 S2():a(0) { }
125};
126const S2 b; // expected-note 2 {{'b' defined here}}
127const S2 ba[5];
128class S3 {
129 int a;
130public:
131 S3():a(0) { }
132};
133const S3 ca[5];
134class S4 {
135 int a;
136 S4();
137public:
138 S4(int v):a(v) { }
139};
140class S5 {
141 int a;
142 S5():a(0) {}
143public:
144 S5(int v):a(v) { }
145};
146
147S3 h;
148#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
149
150template<class I, class C> int foomain(I argc, C **argv) {
151 I e(4);
152 I g(5);
153 int i;
154 int &j = i;
155
156#pragma omp target
157#pragma omp teams
158#pragma omp distribute simd linear // expected-error {{expected '(' after 'linear'}}
159 for (int k = 0; k < argc; ++k) ++k;
160
161#pragma omp target
162#pragma omp teams
163#pragma omp distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
164 for (int k = 0; k < argc; ++k) ++k;
165
166#pragma omp target
167#pragma omp teams
168#pragma omp distribute simd linear () // expected-error {{expected expression}}
169 for (int k = 0; k < argc; ++k) ++k;
170
Alexey Bataev2b86f212017-11-29 21:31:48 +0000171// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000172#pragma omp target
173#pragma omp teams
174#pragma omp distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
175 for (int k = 0; k < argc; ++k) ++k;
176
Alexey Bataev2b86f212017-11-29 21:31:48 +0000177// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000178#pragma omp target
179#pragma omp teams
180#pragma omp distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
181 for (int k = 0; k < argc; ++k) ++k;
182
183#pragma omp target
184#pragma omp teams
185#pragma omp distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
186 for (int k = 0; k < argc; ++k) ++k;
187
Alexey Bataev2b86f212017-11-29 21:31:48 +0000188// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000189#pragma omp target
190#pragma omp teams
191#pragma omp distribute simd linear (argc : 5)
192 for (int k = 0; k < argc; ++k) ++k;
193
194#pragma omp target
195#pragma omp teams
196#pragma omp distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}
197 for (int k = 0; k < argc; ++k) ++k;
198
199#pragma omp target
200#pragma omp teams
Joel E. Dennybae586f2019-01-04 22:12:13 +0000201#pragma omp distribute simd linear (a, b:B::ib) // expected-error {{linear variable with incomplete type 'S1'}} expected-error {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000202 for (int k = 0; k < argc; ++k) ++k;
203
204#pragma omp target
205#pragma omp teams
206#pragma omp distribute simd linear (argv[1]) // expected-error {{expected variable name}}
207 for (int k = 0; k < argc; ++k) ++k;
208
Alexey Bataev2b86f212017-11-29 21:31:48 +0000209// expected-error@+3 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000210#pragma omp target
211#pragma omp teams
212#pragma omp distribute simd linear(e, g)
213 for (int k = 0; k < argc; ++k) ++k;
214
215#pragma omp target
216#pragma omp teams
217#pragma omp distribute simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
218 for (int k = 0; k < argc; ++k) ++k;
219
Alexey Bataev2b86f212017-11-29 21:31:48 +0000220// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000221#pragma omp target
222#pragma omp teams
223#pragma omp distribute simd linear(i)
224 for (int k = 0; k < argc; ++k) ++k;
225
Kelvin Li787f3fc2016-07-06 04:45:38 +0000226 return 0;
227}
228
229namespace A {
230double x;
231#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
232}
233namespace C {
234using A::x;
235}
236
237int main(int argc, char **argv) {
238 double darr[100];
239 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
240 test_template<-4>(darr, 4);
241 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
242 test_warn<0>();
243
244 S4 e(4); // expected-note {{'e' defined here}}
245 S5 g(5); // expected-note {{'g' defined here}}
246 int i;
247 int &j = i;
248
249#pragma omp target
250#pragma omp teams
251#pragma omp distribute simd linear // expected-error {{expected '(' after 'linear'}}
252 for (int k = 0; k < argc; ++k) ++k;
253
254#pragma omp target
255#pragma omp teams
256#pragma omp distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
257 for (int k = 0; k < argc; ++k) ++k;
258
259#pragma omp target
260#pragma omp teams
261#pragma omp distribute simd linear () // expected-error {{expected expression}}
262 for (int k = 0; k < argc; ++k) ++k;
263
Alexey Bataev2b86f212017-11-29 21:31:48 +0000264// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000265#pragma omp target
266#pragma omp teams
267#pragma omp distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
268 for (int k = 0; k < argc; ++k) ++k;
269
Alexey Bataev2b86f212017-11-29 21:31:48 +0000270// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000271#pragma omp target
272#pragma omp teams
273#pragma omp distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
274 for (int k = 0; k < argc; ++k) ++k;
275
276#pragma omp target
277#pragma omp teams
278#pragma omp distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
279 for (int k = 0; k < argc; ++k) ++k;
280
Alexey Bataev2b86f212017-11-29 21:31:48 +0000281// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000282#pragma omp target
283#pragma omp teams
Alexey Bataeve04483e2019-03-27 14:14:31 +0000284#pragma omp distribute simd linear (argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000285 for (int k = 0; k < argc; ++k) ++k;
286
287#pragma omp target
288#pragma omp teams
289#pragma omp distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}
290 for (int k = 0; k < argc; ++k) ++k;
291
292
293#pragma omp target
294#pragma omp teams
Joel E. Dennybae586f2019-01-04 22:12:13 +0000295#pragma omp distribute simd linear (a, b) // expected-error {{linear variable with incomplete type 'S1'}} expected-error {{argument of a linear clause should be of integral or pointer type, not 'S2'}} expected-warning {{Non-trivial type 'const S2' is mapped, only trivial types are guaranteed to be mapped correctly}} expected-error {{incomplete type 'S1' where a complete type is required}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000296 for (int k = 0; k < argc; ++k) ++k;
297
298#pragma omp target
299#pragma omp teams
300#pragma omp distribute simd linear (argv[1]) // expected-error {{expected variable name}}
301 for (int k = 0; k < argc; ++k) ++k;
302
303#pragma omp target
304#pragma omp teams
Alexey Bataevf07946e2018-10-29 20:17:42 +0000305#pragma omp distribute simd linear(e, g) // expected-error {{argument of a linear clause should be of integral or pointer type, not 'S4'}} expected-error {{argument of a linear clause should be of integral or pointer type, not 'S5'}} expected-warning {{Non-trivial type 'S4' is mapped, only trivial types are guaranteed to be mapped correctly}} expected-warning {{Non-trivial type 'S5' is mapped, only trivial types are guaranteed to be mapped correctly}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000306 for (int k = 0; k < argc; ++k) ++k;
307
308#pragma omp target
309#pragma omp teams
310#pragma omp distribute simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
311 for (int k = 0; k < argc; ++k) ++k;
312
313 #pragma omp parallel
314 {
Alexey Bataev2b86f212017-11-29 21:31:48 +0000315 int k;
Kelvin Li787f3fc2016-07-06 04:45:38 +0000316 #pragma omp target
317 #pragma omp teams
Alexey Bataev2b86f212017-11-29 21:31:48 +0000318 #pragma omp distribute simd linear(k)
319 for (k = 0; k < argc; ++k) ++k;
Kelvin Li787f3fc2016-07-06 04:45:38 +0000320
321 #pragma omp target
322 #pragma omp teams
Alexey Bataev2b86f212017-11-29 21:31:48 +0000323 #pragma omp distribute simd linear(k : 4)
324 for (k = 0; k < argc; k+=4) { }
Kelvin Li787f3fc2016-07-06 04:45:38 +0000325 }
326
Kelvin Li787f3fc2016-07-06 04:45:38 +0000327 foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
328 return 0;
329}
330