blob: e5c2aceea8334fa48a9371ad1aa816529b990b02 [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
Alexey Bataeve04483e2019-03-27 14:14:31 +00005extern int omp_default_mem_alloc;
Kelvin Li787f3fc2016-07-06 04:45:38 +00006namespace X {
7 int x;
8};
9
10struct B {
11 static int ib; // expected-note {{'B::ib' declared here}}
12 static int bfoo() { return 8; }
13};
14
15int bfoo() { return 4; }
16
17int z;
18const int C1 = 1;
19const int C2 = 2;
20void test_linear_colons()
21{
22 int B = 0;
23
Alexey Bataev2b86f212017-11-29 21:31:48 +000024// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000025#pragma omp target
26#pragma omp teams
27#pragma omp distribute simd linear(B:bfoo())
28 for (int i = 0; i < 10; ++i) ;
29
Alexey Bataev2b86f212017-11-29 21:31:48 +000030// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000031#pragma omp target
32#pragma omp teams
33#pragma omp distribute simd linear(B::ib:B:bfoo()) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'}}
34 for (int i = 0; i < 10; ++i) ;
35
Alexey Bataev2b86f212017-11-29 21:31:48 +000036// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000037#pragma omp target
38#pragma omp teams
39#pragma omp distribute simd linear(B:ib) // expected-error {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
40 for (int i = 0; i < 10; ++i) ;
41
Alexey Bataev2b86f212017-11-29 21:31:48 +000042// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000043#pragma omp target
44#pragma omp teams
45#pragma omp distribute simd linear(z:B:ib) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}}
46 for (int i = 0; i < 10; ++i) ;
47
Alexey Bataev2b86f212017-11-29 21:31:48 +000048// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000049#pragma omp target
50#pragma omp teams
51#pragma omp distribute simd linear(B:B::bfoo())
52 for (int i = 0; i < 10; ++i) ;
53
Alexey Bataev2b86f212017-11-29 21:31:48 +000054// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000055#pragma omp target
56#pragma omp teams
57#pragma omp distribute simd linear(X::x : ::z)
58 for (int i = 0; i < 10; ++i) ;
59
Alexey Bataev2b86f212017-11-29 21:31:48 +000060// expected-error@+3 3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000061#pragma omp target
62#pragma omp teams
63#pragma omp distribute simd linear(B,::z, X::x)
64 for (int i = 0; i < 10; ++i) ;
65
Alexey Bataev2b86f212017-11-29 21:31:48 +000066// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000067#pragma omp target
68#pragma omp teams
69#pragma omp distribute simd linear(::z)
70 for (int i = 0; i < 10; ++i) ;
71
72#pragma omp target
73#pragma omp teams
74#pragma omp distribute simd linear(B::bfoo()) // expected-error {{expected variable name}}
75 for (int i = 0; i < 10; ++i) ;
76
Alexey Bataev2b86f212017-11-29 21:31:48 +000077// expected-error@+3 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +000078#pragma omp target
79#pragma omp teams
80#pragma omp distribute simd linear(B::ib,B:C1+C2)
81 for (int i = 0; i < 10; ++i) ;
82}
83
84template<int L, class T, class N> T test_template(T* arr, N num) {
85 N i;
86 T sum = (T)0;
87 T ind2 = - num * L; // expected-note {{'ind2' defined here}}
88
89#pragma omp target
90#pragma omp teams
91#pragma omp distribute simd linear(ind2:L) // expected-error {{argument of a linear clause should be of integral or pointer type}}
92 for (i = 0; i < num; ++i) {
93 T cur = arr[(int)ind2];
94 ind2 += L;
95 sum += cur;
96 }
97 return T();
98}
99
100template<int LEN> int test_warn() {
101 int ind2 = 0;
102 #pragma omp target
103 #pragma omp teams
104 #pragma omp parallel for simd linear(ind2:LEN) // expected-warning {{zero linear step (ind2 should probably be const)}}
105 for (int i = 0; i < 100; i++) {
106 ind2 += LEN;
107 }
108 return ind2;
109}
110
111struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
112extern S1 a;
113class S2 {
114 mutable int a;
115public:
116 S2():a(0) { }
117};
118const S2 b; // expected-note 2 {{'b' defined here}}
119const S2 ba[5];
120class S3 {
121 int a;
122public:
123 S3():a(0) { }
124};
125const S3 ca[5];
126class S4 {
127 int a;
128 S4();
129public:
130 S4(int v):a(v) { }
131};
132class S5 {
133 int a;
134 S5():a(0) {}
135public:
136 S5(int v):a(v) { }
137};
138
139S3 h;
140#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
141
142template<class I, class C> int foomain(I argc, C **argv) {
143 I e(4);
144 I g(5);
145 int i;
146 int &j = i;
147
148#pragma omp target
149#pragma omp teams
150#pragma omp distribute simd linear // expected-error {{expected '(' after 'linear'}}
151 for (int k = 0; k < argc; ++k) ++k;
152
153#pragma omp target
154#pragma omp teams
155#pragma omp distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
156 for (int k = 0; k < argc; ++k) ++k;
157
158#pragma omp target
159#pragma omp teams
160#pragma omp distribute simd linear () // expected-error {{expected expression}}
161 for (int k = 0; k < argc; ++k) ++k;
162
Alexey Bataev2b86f212017-11-29 21:31:48 +0000163// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000164#pragma omp target
165#pragma omp teams
166#pragma omp distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
167 for (int k = 0; k < argc; ++k) ++k;
168
Alexey Bataev2b86f212017-11-29 21:31:48 +0000169// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000170#pragma omp target
171#pragma omp teams
172#pragma omp distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
173 for (int k = 0; k < argc; ++k) ++k;
174
175#pragma omp target
176#pragma omp teams
177#pragma omp distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
178 for (int k = 0; k < argc; ++k) ++k;
179
Alexey Bataev2b86f212017-11-29 21:31:48 +0000180// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000181#pragma omp target
182#pragma omp teams
183#pragma omp distribute simd linear (argc : 5)
184 for (int k = 0; k < argc; ++k) ++k;
185
186#pragma omp target
187#pragma omp teams
188#pragma omp distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}
189 for (int k = 0; k < argc; ++k) ++k;
190
191#pragma omp target
192#pragma omp teams
Joel E. Dennybae586f2019-01-04 22:12:13 +0000193#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 +0000194 for (int k = 0; k < argc; ++k) ++k;
195
196#pragma omp target
197#pragma omp teams
198#pragma omp distribute simd linear (argv[1]) // expected-error {{expected variable name}}
199 for (int k = 0; k < argc; ++k) ++k;
200
Alexey Bataev2b86f212017-11-29 21:31:48 +0000201// expected-error@+3 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000202#pragma omp target
203#pragma omp teams
204#pragma omp distribute simd linear(e, g)
205 for (int k = 0; k < argc; ++k) ++k;
206
207#pragma omp target
208#pragma omp teams
209#pragma omp distribute simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
210 for (int k = 0; k < argc; ++k) ++k;
211
Alexey Bataev2b86f212017-11-29 21:31:48 +0000212// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000213#pragma omp target
214#pragma omp teams
215#pragma omp distribute simd linear(i)
216 for (int k = 0; k < argc; ++k) ++k;
217
Kelvin Li787f3fc2016-07-06 04:45:38 +0000218 return 0;
219}
220
221namespace A {
222double x;
223#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
224}
225namespace C {
226using A::x;
227}
228
229int main(int argc, char **argv) {
230 double darr[100];
231 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
232 test_template<-4>(darr, 4);
233 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
234 test_warn<0>();
235
236 S4 e(4); // expected-note {{'e' defined here}}
237 S5 g(5); // expected-note {{'g' defined here}}
238 int i;
239 int &j = i;
240
241#pragma omp target
242#pragma omp teams
243#pragma omp distribute simd linear // expected-error {{expected '(' after 'linear'}}
244 for (int k = 0; k < argc; ++k) ++k;
245
246#pragma omp target
247#pragma omp teams
248#pragma omp distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
249 for (int k = 0; k < argc; ++k) ++k;
250
251#pragma omp target
252#pragma omp teams
253#pragma omp distribute simd linear () // expected-error {{expected expression}}
254 for (int k = 0; k < argc; ++k) ++k;
255
Alexey Bataev2b86f212017-11-29 21:31:48 +0000256// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000257#pragma omp target
258#pragma omp teams
259#pragma omp distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
260 for (int k = 0; k < argc; ++k) ++k;
261
Alexey Bataev2b86f212017-11-29 21:31:48 +0000262// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000263#pragma omp target
264#pragma omp teams
265#pragma omp distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
266 for (int k = 0; k < argc; ++k) ++k;
267
268#pragma omp target
269#pragma omp teams
270#pragma omp distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
271 for (int k = 0; k < argc; ++k) ++k;
272
Alexey Bataev2b86f212017-11-29 21:31:48 +0000273// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Li787f3fc2016-07-06 04:45:38 +0000274#pragma omp target
275#pragma omp teams
Alexey Bataeve04483e2019-03-27 14:14:31 +0000276#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 +0000277 for (int k = 0; k < argc; ++k) ++k;
278
279#pragma omp target
280#pragma omp teams
281#pragma omp distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}
282 for (int k = 0; k < argc; ++k) ++k;
283
284
285#pragma omp target
286#pragma omp teams
Joel E. Dennybae586f2019-01-04 22:12:13 +0000287#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 +0000288 for (int k = 0; k < argc; ++k) ++k;
289
290#pragma omp target
291#pragma omp teams
292#pragma omp distribute simd linear (argv[1]) // expected-error {{expected variable name}}
293 for (int k = 0; k < argc; ++k) ++k;
294
295#pragma omp target
296#pragma omp teams
Alexey Bataevf07946e2018-10-29 20:17:42 +0000297#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 +0000298 for (int k = 0; k < argc; ++k) ++k;
299
300#pragma omp target
301#pragma omp teams
302#pragma omp distribute simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
303 for (int k = 0; k < argc; ++k) ++k;
304
305 #pragma omp parallel
306 {
Alexey Bataev2b86f212017-11-29 21:31:48 +0000307 int k;
Kelvin Li787f3fc2016-07-06 04:45:38 +0000308 #pragma omp target
309 #pragma omp teams
Alexey Bataev2b86f212017-11-29 21:31:48 +0000310 #pragma omp distribute simd linear(k)
311 for (k = 0; k < argc; ++k) ++k;
Kelvin Li787f3fc2016-07-06 04:45:38 +0000312
313 #pragma omp target
314 #pragma omp teams
Alexey Bataev2b86f212017-11-29 21:31:48 +0000315 #pragma omp distribute simd linear(k : 4)
316 for (k = 0; k < argc; k+=4) { }
Kelvin Li787f3fc2016-07-06 04:45:38 +0000317 }
318
Kelvin Li787f3fc2016-07-06 04:45:38 +0000319 foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
320 return 0;
321}
322