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