blob: 631b43a12096ee77e92e12a656e5d072a65d06b1 [file] [log] [blame]
Kelvin Li787f3fc2016-07-06 04:45:38 +00001// RUN: %clang_cc1 -verify -fopenmp %s
2
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00003// RUN: %clang_cc1 -verify -fopenmp-simd %s
4
Kelvin Li787f3fc2016-07-06 04:45:38 +00005namespace X {
6 int x;
7};
8
9struct B {
10 static int ib; // expected-note {{'B::ib' declared here}}
11 static int bfoo() { return 8; }
12};
13
14int bfoo() { return 4; }
15
16int z;
17const int C1 = 1;
18const int C2 = 2;
19void test_linear_colons()
20{
21 int B = 0;
22
Alexey Bataev2b86f212017-11-29 21:31:48 +000023// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000024#pragma omp target
25#pragma omp teams
26#pragma omp distribute simd linear(B:bfoo())
27 for (int i = 0; i < 10; ++i) ;
28
Alexey Bataev2b86f212017-11-29 21:31:48 +000029// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000030#pragma omp target
31#pragma omp teams
32#pragma omp distribute simd linear(B::ib:B:bfoo()) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'}}
33 for (int i = 0; i < 10; ++i) ;
34
Alexey Bataev2b86f212017-11-29 21:31:48 +000035// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000036#pragma omp target
37#pragma omp teams
38#pragma omp distribute simd linear(B:ib) // expected-error {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
39 for (int i = 0; i < 10; ++i) ;
40
Alexey Bataev2b86f212017-11-29 21:31:48 +000041// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000042#pragma omp target
43#pragma omp teams
44#pragma omp distribute simd linear(z:B:ib) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}}
45 for (int i = 0; i < 10; ++i) ;
46
Alexey Bataev2b86f212017-11-29 21:31:48 +000047// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000048#pragma omp target
49#pragma omp teams
50#pragma omp distribute simd linear(B:B::bfoo())
51 for (int i = 0; i < 10; ++i) ;
52
Alexey Bataev2b86f212017-11-29 21:31:48 +000053// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000054#pragma omp target
55#pragma omp teams
56#pragma omp distribute simd linear(X::x : ::z)
57 for (int i = 0; i < 10; ++i) ;
58
Alexey Bataev2b86f212017-11-29 21:31:48 +000059// expected-error@+3 3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000060#pragma omp target
61#pragma omp teams
62#pragma omp distribute simd linear(B,::z, X::x)
63 for (int i = 0; i < 10; ++i) ;
64
Alexey Bataev2b86f212017-11-29 21:31:48 +000065// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000066#pragma omp target
67#pragma omp teams
68#pragma omp distribute simd linear(::z)
69 for (int i = 0; i < 10; ++i) ;
70
71#pragma omp target
72#pragma omp teams
73#pragma omp distribute simd linear(B::bfoo()) // expected-error {{expected variable name}}
74 for (int i = 0; i < 10; ++i) ;
75
Alexey Bataev2b86f212017-11-29 21:31:48 +000076// expected-error@+3 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000077#pragma omp target
78#pragma omp teams
79#pragma omp distribute simd linear(B::ib,B:C1+C2)
80 for (int i = 0; i < 10; ++i) ;
81}
82
83template<int L, class T, class N> T test_template(T* arr, N num) {
84 N i;
85 T sum = (T)0;
86 T ind2 = - num * L; // expected-note {{'ind2' defined here}}
87
88#pragma omp target
89#pragma omp teams
90#pragma omp distribute simd linear(ind2:L) // expected-error {{argument of a linear clause should be of integral or pointer type}}
91 for (i = 0; i < num; ++i) {
92 T cur = arr[(int)ind2];
93 ind2 += L;
94 sum += cur;
95 }
96 return T();
97}
98
99template<int LEN> int test_warn() {
100 int ind2 = 0;
101 #pragma omp target
102 #pragma omp teams
103 #pragma omp parallel for simd linear(ind2:LEN) // expected-warning {{zero linear step (ind2 should probably be const)}}
104 for (int i = 0; i < 100; i++) {
105 ind2 += LEN;
106 }
107 return ind2;
108}
109
110struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
111extern S1 a;
112class S2 {
113 mutable int a;
114public:
115 S2():a(0) { }
116};
117const S2 b; // expected-note 2 {{'b' defined here}}
118const S2 ba[5];
119class S3 {
120 int a;
121public:
122 S3():a(0) { }
123};
124const S3 ca[5];
125class S4 {
126 int a;
127 S4();
128public:
129 S4(int v):a(v) { }
130};
131class S5 {
132 int a;
133 S5():a(0) {}
134public:
135 S5(int v):a(v) { }
136};
137
138S3 h;
139#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
140
141template<class I, class C> int foomain(I argc, C **argv) {
142 I e(4);
143 I g(5);
144 int i;
145 int &j = i;
146
147#pragma omp target
148#pragma omp teams
149#pragma omp distribute simd linear // expected-error {{expected '(' after 'linear'}}
150 for (int k = 0; k < argc; ++k) ++k;
151
152#pragma omp target
153#pragma omp teams
154#pragma omp distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
155 for (int k = 0; k < argc; ++k) ++k;
156
157#pragma omp target
158#pragma omp teams
159#pragma omp distribute simd linear () // expected-error {{expected expression}}
160 for (int k = 0; k < argc; ++k) ++k;
161
Alexey Bataev2b86f212017-11-29 21:31:48 +0000162// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000163#pragma omp target
164#pragma omp teams
165#pragma omp distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
166 for (int k = 0; k < argc; ++k) ++k;
167
Alexey Bataev2b86f212017-11-29 21:31:48 +0000168// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000169#pragma omp target
170#pragma omp teams
171#pragma omp distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
172 for (int k = 0; k < argc; ++k) ++k;
173
174#pragma omp target
175#pragma omp teams
176#pragma omp distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
177 for (int k = 0; k < argc; ++k) ++k;
178
Alexey Bataev2b86f212017-11-29 21:31:48 +0000179// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000180#pragma omp target
181#pragma omp teams
182#pragma omp distribute simd linear (argc : 5)
183 for (int k = 0; k < argc; ++k) ++k;
184
185#pragma omp target
186#pragma omp teams
187#pragma omp distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}
188 for (int k = 0; k < argc; ++k) ++k;
189
190#pragma omp target
191#pragma omp teams
Joel E. Dennybae586f2019-01-04 22:12:13 +0000192#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 +0000193 for (int k = 0; k < argc; ++k) ++k;
194
195#pragma omp target
196#pragma omp teams
197#pragma omp distribute simd linear (argv[1]) // expected-error {{expected variable name}}
198 for (int k = 0; k < argc; ++k) ++k;
199
Alexey Bataev2b86f212017-11-29 21:31:48 +0000200// expected-error@+3 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000201#pragma omp target
202#pragma omp teams
203#pragma omp distribute simd linear(e, g)
204 for (int k = 0; k < argc; ++k) ++k;
205
206#pragma omp target
207#pragma omp teams
208#pragma omp distribute simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
209 for (int k = 0; k < argc; ++k) ++k;
210
Alexey Bataev2b86f212017-11-29 21:31:48 +0000211// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000212#pragma omp target
213#pragma omp teams
214#pragma omp distribute simd linear(i)
215 for (int k = 0; k < argc; ++k) ++k;
216
Kelvin Li787f3fc2016-07-06 04:45:38 +0000217 return 0;
218}
219
220namespace A {
221double x;
222#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
223}
224namespace C {
225using A::x;
226}
227
228int main(int argc, char **argv) {
229 double darr[100];
230 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
231 test_template<-4>(darr, 4);
232 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
233 test_warn<0>();
234
235 S4 e(4); // expected-note {{'e' defined here}}
236 S5 g(5); // expected-note {{'g' defined here}}
237 int i;
238 int &j = i;
239
240#pragma omp target
241#pragma omp teams
242#pragma omp distribute simd linear // expected-error {{expected '(' after 'linear'}}
243 for (int k = 0; k < argc; ++k) ++k;
244
245#pragma omp target
246#pragma omp teams
247#pragma omp distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
248 for (int k = 0; k < argc; ++k) ++k;
249
250#pragma omp target
251#pragma omp teams
252#pragma omp distribute simd linear () // expected-error {{expected expression}}
253 for (int k = 0; k < argc; ++k) ++k;
254
Alexey Bataev2b86f212017-11-29 21:31:48 +0000255// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000256#pragma omp target
257#pragma omp teams
258#pragma omp distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
259 for (int k = 0; k < argc; ++k) ++k;
260
Alexey Bataev2b86f212017-11-29 21:31:48 +0000261// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000262#pragma omp target
263#pragma omp teams
264#pragma omp distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
265 for (int k = 0; k < argc; ++k) ++k;
266
267#pragma omp target
268#pragma omp teams
269#pragma omp distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
270 for (int k = 0; k < argc; ++k) ++k;
271
Alexey Bataev2b86f212017-11-29 21:31:48 +0000272// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000273#pragma omp target
274#pragma omp teams
275#pragma omp distribute simd linear (argc)
276 for (int k = 0; k < argc; ++k) ++k;
277
278#pragma omp target
279#pragma omp teams
280#pragma omp distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}
281 for (int k = 0; k < argc; ++k) ++k;
282
283
284#pragma omp target
285#pragma omp teams
Joel E. Dennybae586f2019-01-04 22:12:13 +0000286#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 +0000287 for (int k = 0; k < argc; ++k) ++k;
288
289#pragma omp target
290#pragma omp teams
291#pragma omp distribute simd linear (argv[1]) // expected-error {{expected variable name}}
292 for (int k = 0; k < argc; ++k) ++k;
293
294#pragma omp target
295#pragma omp teams
Alexey Bataevf07946e2018-10-29 20:17:42 +0000296#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 +0000297 for (int k = 0; k < argc; ++k) ++k;
298
299#pragma omp target
300#pragma omp teams
301#pragma omp distribute simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
302 for (int k = 0; k < argc; ++k) ++k;
303
304 #pragma omp parallel
305 {
Alexey Bataev2b86f212017-11-29 21:31:48 +0000306 int k;
Kelvin Li787f3fc2016-07-06 04:45:38 +0000307 #pragma omp target
308 #pragma omp teams
Alexey Bataev2b86f212017-11-29 21:31:48 +0000309 #pragma omp distribute simd linear(k)
310 for (k = 0; k < argc; ++k) ++k;
Kelvin Li787f3fc2016-07-06 04:45:38 +0000311
312 #pragma omp target
313 #pragma omp teams
Alexey Bataev2b86f212017-11-29 21:31:48 +0000314 #pragma omp distribute simd linear(k : 4)
315 for (k = 0; k < argc; k+=4) { }
Kelvin Li787f3fc2016-07-06 04:45:38 +0000316 }
317
Kelvin Li787f3fc2016-07-06 04:45:38 +0000318 foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
319 return 0;
320}
321