Clang Project

clang_source_code/test/OpenMP/distribute_parallel_for_simd_linear_messages.cpp
1// RUN: %clang_cc1 -verify -fopenmp %s -Wno-openmp-target
2
3// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wno-openmp-target
4
5extern int omp_default_mem_alloc;
6namespace 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
24// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
25#pragma omp target
26#pragma omp teams
27#pragma omp distribute parallel for simd linear(B:bfoo())
28  for (int i = 0; i < 10; ++i) ;
29
30// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
31#pragma omp target
32#pragma omp teams
33#pragma omp distribute parallel for 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
36// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
37#pragma omp target
38#pragma omp teams
39#pragma omp distribute parallel for 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
42// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
43#pragma omp target
44#pragma omp teams
45#pragma omp distribute parallel for simd linear(z:B:ib) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}}
46  for (int i = 0; i < 10; ++i) ;
47
48// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
49#pragma omp target
50#pragma omp teams
51#pragma omp distribute parallel for simd linear(B:B::bfoo())
52  for (int i = 0; i < 10; ++i) ;
53
54// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
55#pragma omp target
56#pragma omp teams
57#pragma omp distribute parallel for simd linear(X::x : ::z)
58  for (int i = 0; i < 10; ++i) ;
59
60// expected-error@+3 3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
61#pragma omp target
62#pragma omp teams
63#pragma omp distribute parallel for simd linear(B,::z, X::x)
64  for (int i = 0; i < 10; ++i) ;
65
66// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
67#pragma omp target
68#pragma omp teams
69#pragma omp distribute parallel for simd linear(::z)
70  for (int i = 0; i < 10; ++i) ;
71
72#pragma omp target
73#pragma omp teams
74#pragma omp distribute parallel for simd linear(B::bfoo()) // expected-error {{expected variable name}}
75  for (int i = 0; i < 10; ++i) ;
76
77// expected-error@+3 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
78#pragma omp target
79#pragma omp teams
80#pragma omp distribute parallel for 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 parallel for 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 parallel for 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 parallel for 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 parallel for simd linear () // expected-error {{expected expression}}
161  for (int k = 0; k < argc; ++k) ++k;
162
163// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
164#pragma omp target
165#pragma omp teams
166#pragma omp distribute parallel for simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
167  for (int k = 0; k < argc; ++k) ++k;
168
169// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
170#pragma omp target
171#pragma omp teams
172#pragma omp distribute parallel for 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 parallel for simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
178  for (int k = 0; k < argc; ++k) ++k;
179
180// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
181#pragma omp target
182#pragma omp teams
183#pragma omp distribute parallel for 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 parallel for 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
193#pragma omp distribute parallel for 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'}}
194  for (int k = 0; k < argc; ++k) ++k;
195
196#pragma omp target
197#pragma omp teams
198#pragma omp distribute parallel for simd linear (argv[1]) // expected-error {{expected variable name}}
199  for (int k = 0; k < argc; ++k) ++k;
200
201// expected-error@+3 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
202#pragma omp target
203#pragma omp teams
204#pragma omp distribute parallel for 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 parallel for simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
210  for (int k = 0; k < argc; ++k) ++k;
211
212// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
213#pragma omp target
214#pragma omp teams
215#pragma omp distribute parallel for simd linear(i)
216  for (int k = 0; k < argc; ++k) ++k;
217
218  #pragma omp parallel
219  {
220    int v = 0;
221    int i;
222    int k;
223    #pragma omp target
224    #pragma omp teams
225    #pragma omp distribute parallel for simd linear(k:i)
226    for (k = 0; k < argc; ++k) { i = k; v += i; }
227  }
228
229  return 0;
230}
231
232namespace A {
233double x;
234#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
235}
236namespace C {
237using A::x;
238}
239
240int main(int argc, char **argv) {
241  double darr[100];
242  // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
243  test_template<-4>(darr, 4);
244  // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
245  test_warn<0>();
246
247  S4 e(4); // expected-note {{'e' defined here}}
248  S5 g(5); // expected-note {{'g' defined here}}
249  int i;
250  int &j = i;
251
252#pragma omp target
253#pragma omp teams
254#pragma omp distribute parallel for simd linear // expected-error {{expected '(' after 'linear'}}
255  for (int k = 0; k < argc; ++k) ++k;
256
257#pragma omp target
258#pragma omp teams
259#pragma omp distribute parallel for simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
260  for (int k = 0; k < argc; ++k) ++k;
261
262#pragma omp target
263#pragma omp teams
264#pragma omp distribute parallel for simd linear () // expected-error {{expected expression}}
265  for (int k = 0; k < argc; ++k) ++k;
266
267// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
268#pragma omp target
269#pragma omp teams
270#pragma omp distribute parallel for simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
271  for (int k = 0; k < argc; ++k) ++k;
272
273// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
274#pragma omp target
275#pragma omp teams
276#pragma omp distribute parallel for simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
277  for (int k = 0; k < argc; ++k) ++k;
278
279#pragma omp target
280#pragma omp teams
281#pragma omp distribute parallel for simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
282  for (int k = 0; k < argc; ++k) ++k;
283
284// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
285#pragma omp target
286#pragma omp teams
287#pragma omp distribute parallel for 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 '('}}
288  for (int k = 0; k < argc; ++k) ++k;
289
290#pragma omp target
291#pragma omp teams
292#pragma omp distribute parallel for simd linear (S1) // expected-error {{'S1' does not refer to a value}}
293  for (int k = 0; k < argc; ++k) ++k;
294
295
296#pragma omp target
297#pragma omp teams
298#pragma omp distribute parallel for 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-error {{incomplete type 'S1' where a complete type is required}}
299  for (int k = 0; k < argc; ++k) ++k;
300
301#pragma omp target
302#pragma omp teams
303#pragma omp distribute parallel for simd linear (argv[1]) // expected-error {{expected variable name}}
304  for (int k = 0; k < argc; ++k) ++k;
305
306#pragma omp target
307#pragma omp teams
308#pragma omp distribute parallel for 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'}}
309  for (int k = 0; k < argc; ++k) ++k;
310
311#pragma omp target
312#pragma omp teams
313#pragma omp distribute parallel for simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
314  for (int k = 0; k < argc; ++k) ++k;
315
316  #pragma omp parallel
317  {
318    int i;
319    #pragma omp target
320    #pragma omp teams
321    #pragma omp distribute parallel for simd linear(i)
322      for (i = 0; i < argc; ++i) ++i;
323
324    #pragma omp target
325    #pragma omp teams
326    #pragma omp distribute parallel for simd linear(i : 4)
327      for (i = 0; i < argc; ++i) { ++i; i += 4; }
328  }
329
330  foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
331  return 0;
332}
333
334