blob: e4d71fee82508e058bf98c5b86a3d9561560fcad [file] [log] [blame]
Kelvin Li787f3fc2016-07-06 04:45:38 +00001// RUN: %clang_cc1 -verify -fopenmp %s
2
3namespace X {
4 int x;
5};
6
7struct B {
8 static int ib; // expected-note {{'B::ib' declared here}}
9 static int bfoo() { return 8; }
10};
11
12int bfoo() { return 4; }
13
14int z;
15const int C1 = 1;
16const int C2 = 2;
17void test_linear_colons()
18{
19 int B = 0;
20
Alexey Bataev2b86f212017-11-29 21:31:48 +000021// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000022#pragma omp target
23#pragma omp teams
24#pragma omp distribute simd linear(B:bfoo())
25 for (int i = 0; i < 10; ++i) ;
26
Alexey Bataev2b86f212017-11-29 21:31:48 +000027// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000028#pragma omp target
29#pragma omp teams
30#pragma omp distribute simd linear(B::ib:B:bfoo()) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'}}
31 for (int i = 0; i < 10; ++i) ;
32
Alexey Bataev2b86f212017-11-29 21:31:48 +000033// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000034#pragma omp target
35#pragma omp teams
36#pragma omp distribute simd linear(B:ib) // expected-error {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
37 for (int i = 0; i < 10; ++i) ;
38
Alexey Bataev2b86f212017-11-29 21:31:48 +000039// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000040#pragma omp target
41#pragma omp teams
42#pragma omp distribute simd linear(z:B:ib) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}}
43 for (int i = 0; i < 10; ++i) ;
44
Alexey Bataev2b86f212017-11-29 21:31:48 +000045// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000046#pragma omp target
47#pragma omp teams
48#pragma omp distribute simd linear(B:B::bfoo())
49 for (int i = 0; i < 10; ++i) ;
50
Alexey Bataev2b86f212017-11-29 21:31:48 +000051// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000052#pragma omp target
53#pragma omp teams
54#pragma omp distribute simd linear(X::x : ::z)
55 for (int i = 0; i < 10; ++i) ;
56
Alexey Bataev2b86f212017-11-29 21:31:48 +000057// expected-error@+3 3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000058#pragma omp target
59#pragma omp teams
60#pragma omp distribute simd linear(B,::z, X::x)
61 for (int i = 0; i < 10; ++i) ;
62
Alexey Bataev2b86f212017-11-29 21:31:48 +000063// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000064#pragma omp target
65#pragma omp teams
66#pragma omp distribute simd linear(::z)
67 for (int i = 0; i < 10; ++i) ;
68
69#pragma omp target
70#pragma omp teams
71#pragma omp distribute simd linear(B::bfoo()) // expected-error {{expected variable name}}
72 for (int i = 0; i < 10; ++i) ;
73
Alexey Bataev2b86f212017-11-29 21:31:48 +000074// expected-error@+3 2 {{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(B::ib,B:C1+C2)
78 for (int i = 0; i < 10; ++i) ;
79}
80
81template<int L, class T, class N> T test_template(T* arr, N num) {
82 N i;
83 T sum = (T)0;
84 T ind2 = - num * L; // expected-note {{'ind2' defined here}}
85
86#pragma omp target
87#pragma omp teams
88#pragma omp distribute simd linear(ind2:L) // expected-error {{argument of a linear clause should be of integral or pointer type}}
89 for (i = 0; i < num; ++i) {
90 T cur = arr[(int)ind2];
91 ind2 += L;
92 sum += cur;
93 }
94 return T();
95}
96
97template<int LEN> int test_warn() {
98 int ind2 = 0;
99 #pragma omp target
100 #pragma omp teams
101 #pragma omp parallel for simd linear(ind2:LEN) // expected-warning {{zero linear step (ind2 should probably be const)}}
102 for (int i = 0; i < 100; i++) {
103 ind2 += LEN;
104 }
105 return ind2;
106}
107
108struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
109extern S1 a;
110class S2 {
111 mutable int a;
112public:
113 S2():a(0) { }
114};
115const S2 b; // expected-note 2 {{'b' defined here}}
116const S2 ba[5];
117class S3 {
118 int a;
119public:
120 S3():a(0) { }
121};
122const S3 ca[5];
123class S4 {
124 int a;
125 S4();
126public:
127 S4(int v):a(v) { }
128};
129class S5 {
130 int a;
131 S5():a(0) {}
132public:
133 S5(int v):a(v) { }
134};
135
136S3 h;
137#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
138
139template<class I, class C> int foomain(I argc, C **argv) {
140 I e(4);
141 I g(5);
142 int i;
143 int &j = i;
144
145#pragma omp target
146#pragma omp teams
147#pragma omp distribute simd linear // expected-error {{expected '(' after 'linear'}}
148 for (int k = 0; k < argc; ++k) ++k;
149
150#pragma omp target
151#pragma omp teams
152#pragma omp distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
153 for (int k = 0; k < argc; ++k) ++k;
154
155#pragma omp target
156#pragma omp teams
157#pragma omp distribute simd linear () // expected-error {{expected expression}}
158 for (int k = 0; k < argc; ++k) ++k;
159
Alexey Bataev2b86f212017-11-29 21:31:48 +0000160// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000161#pragma omp target
162#pragma omp teams
163#pragma omp distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
164 for (int k = 0; k < argc; ++k) ++k;
165
Alexey Bataev2b86f212017-11-29 21:31:48 +0000166// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000167#pragma omp target
168#pragma omp teams
169#pragma omp distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
170 for (int k = 0; k < argc; ++k) ++k;
171
172#pragma omp target
173#pragma omp teams
174#pragma omp distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
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 : 5)
181 for (int k = 0; k < argc; ++k) ++k;
182
183#pragma omp target
184#pragma omp teams
185#pragma omp distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}
186 for (int k = 0; k < argc; ++k) ++k;
187
188#pragma omp target
189#pragma omp teams
190#pragma omp distribute simd linear (a, b:B::ib) // expected-error {{linear variable with incomplete type 'S1'}} expected-error {{const-qualified variable cannot be linear}}
191 for (int k = 0; k < argc; ++k) ++k;
192
193#pragma omp target
194#pragma omp teams
195#pragma omp distribute simd linear (argv[1]) // expected-error {{expected variable name}}
196 for (int k = 0; k < argc; ++k) ++k;
197
Alexey Bataev2b86f212017-11-29 21:31:48 +0000198// expected-error@+3 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000199#pragma omp target
200#pragma omp teams
201#pragma omp distribute simd linear(e, g)
202 for (int k = 0; k < argc; ++k) ++k;
203
204#pragma omp target
205#pragma omp teams
206#pragma omp distribute simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
207 for (int k = 0; k < argc; ++k) ++k;
208
Alexey Bataev2b86f212017-11-29 21:31:48 +0000209// expected-error@+3 {{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(i)
213 for (int k = 0; k < argc; ++k) ++k;
214
Kelvin Li787f3fc2016-07-06 04:45:38 +0000215 return 0;
216}
217
218namespace A {
219double x;
220#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
221}
222namespace C {
223using A::x;
224}
225
226int main(int argc, char **argv) {
227 double darr[100];
228 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
229 test_template<-4>(darr, 4);
230 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
231 test_warn<0>();
232
233 S4 e(4); // expected-note {{'e' defined here}}
234 S5 g(5); // expected-note {{'g' defined here}}
235 int i;
236 int &j = i;
237
238#pragma omp target
239#pragma omp teams
240#pragma omp distribute simd linear // expected-error {{expected '(' after 'linear'}}
241 for (int k = 0; k < argc; ++k) ++k;
242
243#pragma omp target
244#pragma omp teams
245#pragma omp distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
246 for (int k = 0; k < argc; ++k) ++k;
247
248#pragma omp target
249#pragma omp teams
250#pragma omp distribute simd linear () // expected-error {{expected expression}}
251 for (int k = 0; k < argc; ++k) ++k;
252
Alexey Bataev2b86f212017-11-29 21:31:48 +0000253// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000254#pragma omp target
255#pragma omp teams
256#pragma omp distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
257 for (int k = 0; k < argc; ++k) ++k;
258
Alexey Bataev2b86f212017-11-29 21:31:48 +0000259// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000260#pragma omp target
261#pragma omp teams
262#pragma omp distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
263 for (int k = 0; k < argc; ++k) ++k;
264
265#pragma omp target
266#pragma omp teams
267#pragma omp distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
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)
274 for (int k = 0; k < argc; ++k) ++k;
275
276#pragma omp target
277#pragma omp teams
278#pragma omp distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}
279 for (int k = 0; k < argc; ++k) ++k;
280
281
282#pragma omp target
283#pragma omp teams
284#pragma omp distribute simd linear (a, b) // expected-error {{linear variable with incomplete type 'S1'}} expected-error {{const-qualified variable cannot be linear}}
285 for (int k = 0; k < argc; ++k) ++k;
286
287#pragma omp target
288#pragma omp teams
289#pragma omp distribute simd linear (argv[1]) // expected-error {{expected variable name}}
290 for (int k = 0; k < argc; ++k) ++k;
291
292#pragma omp target
293#pragma omp teams
294#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'}}
295 for (int k = 0; k < argc; ++k) ++k;
296
297#pragma omp target
298#pragma omp teams
299#pragma omp distribute simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
300 for (int k = 0; k < argc; ++k) ++k;
301
302 #pragma omp parallel
303 {
Alexey Bataev2b86f212017-11-29 21:31:48 +0000304 int k;
Kelvin Li787f3fc2016-07-06 04:45:38 +0000305 #pragma omp target
306 #pragma omp teams
Alexey Bataev2b86f212017-11-29 21:31:48 +0000307 #pragma omp distribute simd linear(k)
308 for (k = 0; k < argc; ++k) ++k;
Kelvin Li787f3fc2016-07-06 04:45:38 +0000309
310 #pragma omp target
311 #pragma omp teams
Alexey Bataev2b86f212017-11-29 21:31:48 +0000312 #pragma omp distribute simd linear(k : 4)
313 for (k = 0; k < argc; k+=4) { }
Kelvin Li787f3fc2016-07-06 04:45:38 +0000314 }
315
Kelvin Li787f3fc2016-07-06 04:45:38 +0000316 foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
317 return 0;
318}
319