Clang Project

clang_source_code/test/OpenMP/distribute_simd_linear_messages.cpp
1// RUN: %clang_cc1 -verify -fopenmp %s
2
3// RUN: %clang_cc1 -verify -fopenmp-simd %s
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 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 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 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 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 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 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 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 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
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 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
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 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 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
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 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
193#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'}}
194  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
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 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
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 simd linear(i)
216  for (int k = 0; k < argc; ++k) ++k;
217
218  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
256// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
257#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
262// expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
263#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
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 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 '('}}
277  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
287#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}}
288  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
297#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}}
298  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  {
307    int k;
308    #pragma omp target
309    #pragma omp teams
310    #pragma omp distribute simd linear(k)
311      for (k = 0; k < argc; ++k) ++k;
312
313    #pragma omp target
314    #pragma omp teams
315    #pragma omp distribute simd linear(k : 4)
316      for (k = 0; k < argc; k+=4) { }
317  }
318
319  foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
320  return 0;
321}
322
323