Clang Project

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