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