Clang Project

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