1 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 150 -o - %s
2 // RUN: %clang_cc1 -verify -fopenmp -std=c++98 -ferror-limit 150 -o - %s
3 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 -ferror-limit 150 -o - %s
4 
5 // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 150 -o - %s
6 // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++98 -ferror-limit 150 -o - %s
7 // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++11 -ferror-limit 150 -o - %s
8 
9 void foo() {
10 }
11 
12 bool foobool(int argc) {
13   return argc;
14 }
15 
16 void foobar(int &ref) {
17 #pragma omp taskgroup task_reduction(+:ref)
18 #pragma omp taskloop simd in_reduction(+:ref)
19   for (int i = 0; i < 10; ++i)
20   foo();
21 }
22 
23 void foobar1(int &ref) {
24 #pragma omp taskgroup task_reduction(+:ref)
25 #pragma omp taskloop simd in_reduction(-:ref)
26   for (int i = 0; i < 10; ++i)
27   foo();
28 }
29 
30 #pragma omp declare reduction (red:int:omp_out += omp_in)
31 
32 void foobar2(int &ref) {
33 #pragma omp taskgroup task_reduction(+:ref) // expected-note {{previously marked as task_reduction with different reduction operation}}
34 #pragma omp taskloop simd in_reduction(red:ref) // expected-error{{in_reduction variable must have the same reduction operation as in a task_reduction clause}}
35   for (int i = 0; i < 10; ++i)
36   foo();
37 }
38 
39 void foobar3(int &ref) {
40 #pragma omp taskgroup task_reduction(red:ref) // expected-note {{previously marked as task_reduction with different reduction operation}}
41 #pragma omp taskloop simd in_reduction(min:ref)  // expected-error{{in_reduction variable must have the same reduction operation as in a task_reduction clause}}
42   for (int i = 0; i < 10; ++i)
43   foo();
44 }
45 
46 void foobar4(int &ref) {
47 #pragma omp taskloop simd in_reduction(min:ref) // expected-error {{in_reduction variable must appear in a task_reduction clause}}
48   for (int i = 0; i < 10; ++i)
49   foo();
50 }
51 
52 struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
53 extern S1 a;
54 class S2 {
55   mutable int a;
56   S2 &operator+(const S2 &arg) { return (*this); } // expected-note 3 {{implicitly declared private here}}
57 
58 public:
59   S2() : a(0) {}
60   S2(S2 &s2) : a(s2.a) {}
61   static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
62   static const float S2sc; // expected-note 2 {{'S2sc' declared here}}
63 };
64 const float S2::S2sc = 0;
65 S2 b;                     // expected-note 3 {{'b' defined here}}
66 const S2 ba[5];           // expected-note 2 {{'ba' defined here}}
67 class S3 {
68   int a;
69 
70 public:
71   int b;
72   S3() : a(0) {}
73   S3(const S3 &s3) : a(s3.a) {}
74   S3 operator+(const S3 &arg1) { return arg1; }
75 };
76 int operator+(const S3 &arg1, const S3 &arg2) { return 5; }
77 S3 c;               // expected-note 3 {{'c' defined here}}
78 const S3 ca[5];     // expected-note 2 {{'ca' defined here}}
79 extern const int f; // expected-note 4 {{'f' declared here}}
80 class S4 {
81   int a;
82   S4(); // expected-note {{implicitly declared private here}}
83   S4(const S4 &s4);
84   S4 &operator+(const S4 &arg) { return (*this); }
85 
86 public:
87   S4(int v) : a(v) {}
88 };
89 S4 &operator&=(S4 &arg1, S4 &arg2) { return arg1; }
90 class S5 {
91   int a;
92   S5() : a(0) {} // expected-note {{implicitly declared private here}}
93   S5(const S5 &s5) : a(s5.a) {}
94   S5 &operator+(const S5 &arg);
95 
96 public:
97   S5(int v) : a(v) {}
98 };
99 class S6 { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const S6' for 1st argument}}
100 #if __cplusplus >= 201103L // C++11 or later
101 // expected-note@-2 3 {{candidate function (the implicit move assignment operator) not viable}}
102 #endif
103   int a;
104 
105 public:
106   S6() : a(6) {}
107   operator int() { return 6; }
108 } o;
109 
110 S3 h, k;
111 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
112 
113 template <class T>       // expected-note {{declared here}}
114 T tmain(T argc) {
115   const T d = T();       // expected-note 4 {{'d' defined here}}
116   const T da[5] = {T()}; // expected-note 2 {{'da' defined here}}
117   T qa[5] = {T()};
118   T i;
119   T &j = i;                    // expected-note 2 {{'j' defined here}}
120   S3 &p = k;                   // expected-note 2 {{'p' defined here}}
121   const T &r = da[(int)i];     // expected-note 2 {{'r' defined here}}
122   T &q = qa[(int)i];
123   T fl;
124 #pragma omp taskgroup task_reduction(+:argc)
125 #pragma omp taskloop simd in_reduction // expected-error {{expected '(' after 'in_reduction'}}
126   for (int i = 0; i < 10; ++i)
127   foo();
128 #pragma omp taskgroup task_reduction(+:argc)
129 #pragma omp taskloop simd in_reduction + // expected-error {{expected '(' after 'in_reduction'}} expected-warning {{extra tokens at the end of '#pragma omp taskloop simd' are ignored}}
130   for (int i = 0; i < 10; ++i)
131   foo();
132 #pragma omp taskgroup task_reduction(+:argc)
133 #pragma omp taskloop simd in_reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
134   for (int i = 0; i < 10; ++i)
135   foo();
136 #pragma omp taskgroup task_reduction(+:argc)
137 #pragma omp taskloop simd in_reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
138   for (int i = 0; i < 10; ++i)
139   foo();
140 #pragma omp taskgroup task_reduction(+:argc)
141 #pragma omp taskloop simd in_reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
142   for (int i = 0; i < 10; ++i)
143   foo();
144 #pragma omp taskgroup task_reduction(+:argc)
145 #pragma omp taskloop simd in_reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}}
146   for (int i = 0; i < 10; ++i)
147   foo();
148 #pragma omp taskgroup task_reduction(+:argc)
149 #pragma omp taskloop simd in_reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
150   for (int i = 0; i < 10; ++i)
151   foo();
152 #pragma omp taskgroup task_reduction(&:argc) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
153 #pragma omp taskloop simd in_reduction(& : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}}
154   for (int i = 0; i < 10; ++i)
155   foo();
156 #pragma omp taskgroup task_reduction(|:argc) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
157 #pragma omp taskloop simd in_reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}}
158   for (int i = 0; i < 10; ++i)
159   foo();
160 #pragma omp taskloop simd in_reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name, array element or array section}}
161   for (int i = 0; i < 10; ++i)
162   foo();
163 #pragma omp taskloop simd in_reduction(foo : argc) //expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'float'}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'int'}}
164   for (int i = 0; i < 10; ++i)
165   foo();
166 #pragma omp taskgroup task_reduction(&&:argc)
167 #pragma omp taskloop simd in_reduction(&& : argc)
168   for (int i = 0; i < 10; ++i)
169   foo();
170 #pragma omp taskloop simd in_reduction(^ : T) // expected-error {{'T' does not refer to a value}}
171   for (int i = 0; i < 10; ++i)
172   foo();
173 #pragma omp taskgroup task_reduction(+:c)
174 #pragma omp taskloop simd in_reduction(+ : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 3 {{const-qualified variable cannot be in_reduction}} expected-error 2 {{'operator+' is a private member of 'S2'}} expected-error 2 {{in_reduction variable must appear in a task_reduction clause}}
175   for (int i = 0; i < 10; ++i)
176   foo();
177 #pragma omp taskloop simd in_reduction(min : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 4 {{arguments of OpenMP clause 'in_reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 3 {{const-qualified variable cannot be in_reduction}}
178   for (int i = 0; i < 10; ++i)
179   foo();
180 #pragma omp taskloop simd in_reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
181   for (int i = 0; i < 10; ++i)
182   foo();
183 #pragma omp taskloop simd in_reduction(+ : ba) // expected-error {{const-qualified variable cannot be in_reduction}}
184   for (int i = 0; i < 10; ++i)
185   foo();
186 #pragma omp taskloop simd in_reduction(* : ca) // expected-error {{const-qualified variable cannot be in_reduction}}
187   for (int i = 0; i < 10; ++i)
188   foo();
189 #pragma omp taskloop simd in_reduction(- : da) // expected-error {{const-qualified variable cannot be in_reduction}} expected-error {{const-qualified variable cannot be in_reduction}}
190   for (int i = 0; i < 10; ++i)
191   foo();
192 #pragma omp taskloop simd in_reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}} expected-error {{in_reduction variable must appear in a task_reduction clause}}
193   for (int i = 0; i < 10; ++i)
194   foo();
195 #pragma omp taskloop simd in_reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
196   for (int i = 0; i < 10; ++i)
197   foo();
198 #pragma omp taskloop simd in_reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be in_reduction}}
199   for (int i = 0; i < 10; ++i)
200   foo();
201 #pragma omp taskgroup task_reduction(+:k)
202 #pragma omp taskloop simd in_reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}}
203   for (int i = 0; i < 10; ++i)
204   foo();
205 #pragma omp taskloop simd in_reduction(+ : o) // expected-error 2 {{no viable overloaded '='}}
206   for (int i = 0; i < 10; ++i)
207   foo();
208 #pragma omp parallel private(k)
209 #pragma omp taskloop simd in_reduction(+ : p), in_reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'in_reduction' must reference the same object in all threads}}
210   for (int i = 0; i < 10; ++i)
211   foo();
212 #pragma omp taskgroup task_reduction(+:p)
213 #pragma omp taskloop simd in_reduction(+ : p), in_reduction(+ : p) // expected-error 2 {{variable can appear only once in OpenMP 'in_reduction' clause}} expected-note 2 {{previously referenced here}}
214   for (int i = 0; i < 10; ++i)
215   foo();
216 #pragma omp taskloop simd in_reduction(+ : r) // expected-error 2 {{const-qualified variable cannot be in_reduction}}
217   for (int i = 0; i < 10; ++i)
218   foo();
219 #pragma omp parallel shared(i)
220 #pragma omp parallel reduction(min : i)
221 #pragma omp taskloop simd in_reduction(max : j) // expected-error 2 {{argument of OpenMP clause 'in_reduction' must reference the same object in all threads}}
222   for (int i = 0; i < 10; ++i)
223   foo();
224 #pragma omp taskgroup task_reduction(+:fl)
225 {
226 #pragma omp taskloop simd in_reduction(+ : fl)
227   for (int i = 0; i < 10; ++i)
228     foo();
229 #pragma omp taskgroup task_reduction(*:fl) // expected-note 2 {{previously marked as task_reduction with different reduction operation}}
230 {
231 #pragma omp taskloop simd in_reduction(+ : fl) // expected-error 2 {{in_reduction variable must have the same reduction operation as in a task_reduction clause}}
232   for (int i = 0; i < 10; ++i)
233     foo();
234 }
235 }
236 #pragma omp parallel
237 #pragma omp for reduction(- : fl)
238   for (int i = 0; i < 10; ++i)
239 #pragma omp taskgroup task_reduction(+:fl)
240 #pragma omp taskloop simd in_reduction(+ : fl)
241   for (int j = 0; j < 10; ++j)
242     foo();
243 
244   return T();
245 }
246 
247 namespace A {
248 double x;
249 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
250 }
251 namespace B {
252 using A::x;
253 }
254 
255 int main(int argc, char **argv) {
256   const int d = 5;       // expected-note 2 {{'d' defined here}}
257   const int da[5] = {0}; // expected-note {{'da' defined here}}
258   int qa[5] = {0};
259   S4 e(4);
260   S5 g(5);
261   int i;
262   int &j = i;                  // expected-note {{'j' defined here}}
263   S3 &p = k;                   // expected-note 2 {{'p' defined here}}
264   const int &r = da[i];        // expected-note {{'r' defined here}}
265   int &q = qa[i];
266   float fl;
267 #pragma omp taskloop simd in_reduction // expected-error {{expected '(' after 'in_reduction'}}
268   for (int i = 0; i < 10; ++i)
269   foo();
270 #pragma omp taskloop simd in_reduction + // expected-error {{expected '(' after 'in_reduction'}} expected-warning {{extra tokens at the end of '#pragma omp taskloop simd' are ignored}}
271   for (int i = 0; i < 10; ++i)
272   foo();
273 #pragma omp taskloop simd in_reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
274   for (int i = 0; i < 10; ++i)
275   foo();
276 #pragma omp taskloop simd in_reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
277   for (int i = 0; i < 10; ++i)
278   foo();
279 #pragma omp taskloop simd in_reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
280   for (int i = 0; i < 10; ++i)
281   foo();
282 #pragma omp taskloop simd in_reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}}
283   for (int i = 0; i < 10; ++i)
284   foo();
285 #pragma omp taskloop simd in_reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
286   for (int i = 0; i < 10; ++i)
287   foo();
288 #pragma omp taskloop simd in_reduction(foo : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}}
289   for (int i = 0; i < 10; ++i)
290   foo();
291 #pragma omp taskgroup task_reduction(|:argc)
292 #pragma omp taskloop simd in_reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
293   for (int i = 0; i < 10; ++i)
294   foo();
295 #pragma omp taskloop simd in_reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name, array element or array section}}
296   for (int i = 0; i < 10; ++i)
297   foo();
298 #pragma omp taskloop simd in_reduction(~ : argc) // expected-error {{expected unqualified-id}}
299   for (int i = 0; i < 10; ++i)
300   foo();
301 #pragma omp taskgroup task_reduction(&&:argc)
302 #pragma omp taskloop simd in_reduction(&& : argc)
303   for (int i = 0; i < 10; ++i)
304   foo();
305 #pragma omp taskloop simd in_reduction(^ : S1) // expected-error {{'S1' does not refer to a value}}
306   for (int i = 0; i < 10; ++i)
307   foo();
308 #pragma omp taskgroup task_reduction(+:c)
309 #pragma omp taskloop simd in_reduction(+ : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{const-qualified variable cannot be in_reduction}} expected-error {{'operator+' is a private member of 'S2'}} expected-error {{in_reduction variable must appear in a task_reduction clause}}
310   for (int i = 0; i < 10; ++i)
311   foo();
312 #pragma omp taskloop simd in_reduction(min : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{arguments of OpenMP clause 'in_reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 2 {{const-qualified variable cannot be in_reduction}}
313   for (int i = 0; i < 10; ++i)
314   foo();
315 #pragma omp taskloop simd in_reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
316   for (int i = 0; i < 10; ++i)
317   foo();
318 #pragma omp taskloop simd in_reduction(+ : ba) // expected-error {{const-qualified variable cannot be in_reduction}}
319   for (int i = 0; i < 10; ++i)
320   foo();
321 #pragma omp taskloop simd in_reduction(* : ca) // expected-error {{const-qualified variable cannot be in_reduction}}
322   for (int i = 0; i < 10; ++i)
323   foo();
324 #pragma omp taskloop simd in_reduction(- : da) // expected-error {{const-qualified variable cannot be in_reduction}}
325   for (int i = 0; i < 10; ++i)
326   foo();
327 #pragma omp taskloop simd in_reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
328   for (int i = 0; i < 10; ++i)
329   foo();
330 #pragma omp taskloop simd in_reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
331   for (int i = 0; i < 10; ++i)
332   foo();
333 #pragma omp taskloop simd in_reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be in_reduction}}
334   for (int i = 0; i < 10; ++i)
335   foo();
336 #pragma omp taskloop simd in_reduction(& : e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{nvalid operands to binary expression ('S4' and 'S4')}} expected-error {{calling a private constructor of class 'S5'}} expected-error {{invalid operands to binary expression ('S5' and 'S5')}}
337   for (int i = 0; i < 10; ++i)
338   foo();
339 #pragma omp taskgroup task_reduction(+:k)
340 #pragma omp taskloop simd in_reduction(+ : h, k, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be reduction}}
341   for (int i = 0; i < 10; ++i)
342   foo();
343 #pragma omp taskloop simd in_reduction(+ : o) // expected-error {{no viable overloaded '='}}
344   for (int i = 0; i < 10; ++i)
345   foo();
346 #pragma omp parallel private(k)
347 #pragma omp taskloop simd in_reduction(+ : p), in_reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'in_reduction' must reference the same object in all threads}}
348   for (int i = 0; i < 10; ++i)
349   foo();
350 #pragma omp taskgroup task_reduction(+:p)
351 #pragma omp taskloop simd in_reduction(+ : p), in_reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'in_reduction' clause}} expected-note {{previously referenced here}}
352   for (int i = 0; i < 10; ++i)
353   foo();
354 #pragma omp taskloop simd in_reduction(+ : r) // expected-error {{const-qualified variable cannot be in_reduction}}
355   for (int i = 0; i < 10; ++i)
356   foo();
357 #pragma omp parallel shared(i)
358 #pragma omp parallel reduction(min : i)
359 #pragma omp taskloop simd in_reduction(max : j) // expected-error {{argument of OpenMP clause 'in_reduction' must reference the same object in all threads}}
360   for (int i = 0; i < 10; ++i)
361   foo();
362 #pragma omp parallel
363 #pragma omp for private(fl)
364   for (int i = 0; i < 10; ++i)
365 #pragma omp taskgroup task_reduction(+:fl)
366 #pragma omp taskloop simd in_reduction(+ : fl)
367   for (int j = 0; j < 10; ++j)
368     foo();
369 #pragma omp taskgroup task_reduction(+:fl)
370 #pragma omp taskloop simd in_reduction(+ : fl)
371   for (int i = 0; i < 10; ++i)
372     foo();
373   static int m;
374 #pragma omp taskgroup task_reduction(+:m)
375 #pragma omp taskloop simd in_reduction(+ : m) // OK
376   for (int i = 0; i < 10; ++i)
377   m++;
378 
379   return tmain(argc) + tmain(fl); // expected-note {{in instantiation of function template specialization 'tmain<int>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<float>' requested here}}
380 }
381