1 // RUN: %clang_cc1 -verify -fopenmp %s
2 
3 namespace X {
4   int x;
5 };
6 
7 struct B {
8   static int ib; // expected-note {{'B::ib' declared here}}
9   static int bfoo() { return 8; }
10 };
11 
12 int bfoo() { return 4; }
13 
14 int z;
15 const int C1 = 1;
16 const int C2 = 2;
17 void test_linear_colons()
18 {
19   int B = 0;
20 
21 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
22 #pragma omp target
23 #pragma omp teams
24 #pragma omp distribute parallel for simd linear(B:bfoo())
25   for (int i = 0; i < 10; ++i) ;
26 
27 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
28 #pragma omp target
29 #pragma omp teams
30 #pragma omp distribute parallel for 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 
33 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
34 #pragma omp target
35 #pragma omp teams
36 #pragma omp distribute parallel for 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 
39 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
40 #pragma omp target
41 #pragma omp teams
42 #pragma omp distribute parallel for simd linear(z:B:ib) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}}
43   for (int i = 0; i < 10; ++i) ;
44 
45 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
46 #pragma omp target
47 #pragma omp teams
48 #pragma omp distribute parallel for simd linear(B:B::bfoo())
49   for (int i = 0; i < 10; ++i) ;
50 
51 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
52 #pragma omp target
53 #pragma omp teams
54 #pragma omp distribute parallel for simd linear(X::x : ::z)
55   for (int i = 0; i < 10; ++i) ;
56 
57 // expected-error@+3 3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
58 #pragma omp target
59 #pragma omp teams
60 #pragma omp distribute parallel for simd linear(B,::z, X::x)
61   for (int i = 0; i < 10; ++i) ;
62 
63 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
64 #pragma omp target
65 #pragma omp teams
66 #pragma omp distribute parallel for simd linear(::z)
67   for (int i = 0; i < 10; ++i) ;
68 
69 #pragma omp target
70 #pragma omp teams
71 #pragma omp distribute parallel for simd linear(B::bfoo()) // expected-error {{expected variable name}}
72   for (int i = 0; i < 10; ++i) ;
73 
74 // expected-error@+3 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
75 #pragma omp target
76 #pragma omp teams
77 #pragma omp distribute parallel for simd linear(B::ib,B:C1+C2)
78   for (int i = 0; i < 10; ++i) ;
79 }
80 
81 template<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 parallel for 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 
97 template<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 
108 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
109 extern S1 a;
110 class S2 {
111   mutable int a;
112 public:
113   S2():a(0) { }
114 };
115 const S2 b; // expected-note 2 {{'b' defined here}}
116 const S2 ba[5];
117 class S3 {
118   int a;
119 public:
120   S3():a(0) { }
121 };
122 const S3 ca[5];
123 class S4 {
124   int a;
125   S4();
126 public:
127   S4(int v):a(v) { }
128 };
129 class S5 {
130   int a;
131   S5():a(0) {}
132 public:
133   S5(int v):a(v) { }
134 };
135 
136 S3 h;
137 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
138 
139 template<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 parallel for 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 parallel for 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 parallel for simd linear () // expected-error {{expected expression}}
158   for (int k = 0; k < argc; ++k) ++k;
159 
160 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
161 #pragma omp target
162 #pragma omp teams
163 #pragma omp distribute parallel for simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
164   for (int k = 0; k < argc; ++k) ++k;
165 
166 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
167 #pragma omp target
168 #pragma omp teams
169 #pragma omp distribute parallel for 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 parallel for simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
175   for (int k = 0; k < argc; ++k) ++k;
176 
177 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
178 #pragma omp target
179 #pragma omp teams
180 #pragma omp distribute parallel for 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 parallel for 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 parallel for 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 parallel for simd linear (argv[1]) // expected-error {{expected variable name}}
196   for (int k = 0; k < argc; ++k) ++k;
197 
198 // expected-error@+3 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
199 #pragma omp target
200 #pragma omp teams
201 #pragma omp distribute parallel for 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 parallel for simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
207   for (int k = 0; k < argc; ++k) ++k;
208 
209 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
210 #pragma omp target
211 #pragma omp teams
212 #pragma omp distribute parallel for simd linear(i)
213   for (int k = 0; k < argc; ++k) ++k;
214 
215   #pragma omp parallel
216   {
217     int v = 0;
218     int i;
219     int k;
220     #pragma omp target
221     #pragma omp teams
222     #pragma omp distribute parallel for simd linear(k:i)
223     for (k = 0; k < argc; ++k) { i = k; v += i; }
224   }
225 
226   return 0;
227 }
228 
229 namespace A {
230 double x;
231 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
232 }
233 namespace C {
234 using A::x;
235 }
236 
237 int main(int argc, char **argv) {
238   double darr[100];
239   // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
240   test_template<-4>(darr, 4);
241   // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
242   test_warn<0>();
243 
244   S4 e(4); // expected-note {{'e' defined here}}
245   S5 g(5); // expected-note {{'g' defined here}}
246   int i;
247   int &j = i;
248 
249 #pragma omp target
250 #pragma omp teams
251 #pragma omp distribute parallel for simd linear // expected-error {{expected '(' after 'linear'}}
252   for (int k = 0; k < argc; ++k) ++k;
253 
254 #pragma omp target
255 #pragma omp teams
256 #pragma omp distribute parallel for simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
257   for (int k = 0; k < argc; ++k) ++k;
258 
259 #pragma omp target
260 #pragma omp teams
261 #pragma omp distribute parallel for simd linear () // expected-error {{expected expression}}
262   for (int k = 0; k < argc; ++k) ++k;
263 
264 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
265 #pragma omp target
266 #pragma omp teams
267 #pragma omp distribute parallel for simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
268   for (int k = 0; k < argc; ++k) ++k;
269 
270 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
271 #pragma omp target
272 #pragma omp teams
273 #pragma omp distribute parallel for simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
274   for (int k = 0; k < argc; ++k) ++k;
275 
276 #pragma omp target
277 #pragma omp teams
278 #pragma omp distribute parallel for simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
279   for (int k = 0; k < argc; ++k) ++k;
280 
281 // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
282 #pragma omp target
283 #pragma omp teams
284 #pragma omp distribute parallel for simd linear (argc)
285   for (int k = 0; k < argc; ++k) ++k;
286 
287 #pragma omp target
288 #pragma omp teams
289 #pragma omp distribute parallel for simd linear (S1) // expected-error {{'S1' does not refer to a value}}
290   for (int k = 0; k < argc; ++k) ++k;
291 
292 
293 #pragma omp target
294 #pragma omp teams
295 #pragma omp distribute parallel for simd linear (a, b) // expected-error {{linear variable with incomplete type 'S1'}} expected-error {{const-qualified variable cannot be linear}}
296   for (int k = 0; k < argc; ++k) ++k;
297 
298 #pragma omp target
299 #pragma omp teams
300 #pragma omp distribute parallel for simd linear (argv[1]) // expected-error {{expected variable name}}
301   for (int k = 0; k < argc; ++k) ++k;
302 
303 #pragma omp target
304 #pragma omp teams
305 #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'}}
306   for (int k = 0; k < argc; ++k) ++k;
307 
308 #pragma omp target
309 #pragma omp teams
310 #pragma omp distribute parallel for simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
311   for (int k = 0; k < argc; ++k) ++k;
312 
313   #pragma omp parallel
314   {
315     int i;
316     #pragma omp target
317     #pragma omp teams
318     #pragma omp distribute parallel for simd linear(i)
319       for (i = 0; i < argc; ++i) ++i;
320 
321     #pragma omp target
322     #pragma omp teams
323     #pragma omp distribute parallel for simd linear(i : 4)
324       for (i = 0; i < argc; ++i) { ++i; i += 4; }
325   }
326 
327   foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
328   return 0;
329 }
330 
331