Clang Project

clang_source_code/test/OpenMP/teams_distribute_reduction_messages.cpp
1// RUN: %clang_cc1 -verify -fopenmp %s -Wno-openmp-target
2// RUN: %clang_cc1 -verify -fopenmp -std=c++98 %s -Wno-openmp-target
3// RUN: %clang_cc1 -verify -fopenmp -std=c++11 %s -Wno-openmp-target
4
5// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wno-openmp-target
6// RUN: %clang_cc1 -verify -fopenmp-simd -std=c++98 %s -Wno-openmp-target
7// RUN: %clang_cc1 -verify -fopenmp-simd -std=c++11 %s -Wno-openmp-target
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 target
19#pragma omp teams distribute reduction(+:ref)
20  for (int j=0; j<100; j++) foo();
21}
22
23struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
24extern S1 a;
25class S2 {
26  mutable int a;
27  S2 &operator+(const S2 &arg) { return (*this); } // expected-note 3 {{implicitly declared private here}}
28
29public:
30  S2() : a(0) {}
31  S2(S2 &s2) : a(s2.a) {}
32  static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
33  static const float S2sc; // expected-note 2 {{'S2sc' declared here}}
34};
35const float S2::S2sc = 0;
36S2 b;                     // expected-note 3 {{'b' defined here}}
37const S2 ba[5];           // expected-note 2 {{'ba' defined here}}
38class S3 {
39  int a;
40
41public:
42  int b;
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}}
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
84template <class T>       // expected-note {{declared here}}
85T tmain(T argc) {
86  const T d = T();       // expected-note 4 {{'d' defined here}}
87  const T da[5] = {T()}; // expected-note 2 {{'da' defined here}}
88  T qa[5] = {T()};
89  T i;
90  T &j = i;                    // expected-note 4 {{'j' defined here}}
91  S3 &p = k;                   // expected-note 2 {{'p' defined here}}
92  const T &r = da[(int)i];     // expected-note 2 {{'r' defined here}}
93  T &q = qa[(int)i];           // expected-note 2 {{'q' defined here}}
94  T fl;
95#pragma omp target
96#pragma omp teams distribute reduction // expected-error {{expected '(' after 'reduction'}}
97  for (int j=0; j<100; j++) foo();
98#pragma omp target
99#pragma omp teams distribute reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp teams distribute' are ignored}}
100  for (int j=0; j<100; j++) foo();
101#pragma omp target
102#pragma omp teams distribute reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
103  for (int j=0; j<100; j++) foo();
104#pragma omp target
105#pragma omp teams distribute reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
106  for (int j=0; j<100; j++) foo();
107#pragma omp target
108#pragma omp teams distribute reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
109  for (int j=0; j<100; j++) foo();
110#pragma omp target
111#pragma omp teams distribute reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
112  for (int j=0; j<100; j++) foo();
113#pragma omp target
114#pragma omp teams distribute reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
115  for (int j=0; j<100; j++) foo();
116#pragma omp target
117#pragma omp teams distribute reduction(& : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}}
118  for (int j=0; j<100; j++) foo();
119#pragma omp target
120#pragma omp teams distribute reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}}
121  for (int j=0; j<100; j++) foo();
122#pragma omp target
123#pragma omp teams distribute reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name, array element or array section}}
124  for (int j=0; j<100; j++) foo();
125#pragma omp target
126#pragma omp teams distribute 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'}}
127  for (int j=0; j<100; j++) foo();
128#pragma omp target
129#pragma omp teams distribute 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 '('}}
130  for (int j=0; j<100; j++) foo();
131#pragma omp target
132#pragma omp teams distribute reduction(^ : T) // expected-error {{'T' does not refer to a value}}
133  for (int j=0; j<100; j++) foo();
134#pragma omp target
135#pragma omp teams distribute 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'}}
136  for (int j=0; j<100; j++) foo();
137#pragma omp target
138#pragma omp teams distribute 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}}
139  for (int j=0; j<100; j++) foo();
140#pragma omp target
141#pragma omp teams distribute reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
142  for (int j=0; j<100; j++) foo();
143#pragma omp target
144#pragma omp teams distribute reduction(+ : ba) // expected-error {{const-qualified variable cannot be reduction}}
145  for (int j=0; j<100; j++) foo();
146#pragma omp target
147#pragma omp teams distribute reduction(* : ca) // expected-error {{const-qualified variable cannot be reduction}}
148  for (int j=0; j<100; j++) foo();
149#pragma omp target
150#pragma omp teams distribute reduction(- : da) // expected-error {{const-qualified variable cannot be reduction}} expected-error {{const-qualified variable cannot be reduction}}
151  for (int j=0; j<100; j++) foo();
152#pragma omp target
153#pragma omp teams distribute reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
154  for (int j=0; j<100; j++) foo();
155#pragma omp target
156#pragma omp teams distribute reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
157  for (int j=0; j<100; j++) foo();
158#pragma omp target
159#pragma omp teams distribute reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}}
160  for (int j=0; j<100; j++) foo();
161#pragma omp target
162#pragma omp teams distribute reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}}
163  for (int j=0; j<100; j++) foo();
164#pragma omp target
165#pragma omp teams distribute reduction(+ : o) // expected-error 2 {{no viable overloaded '='}}
166  for (int j=0; j<100; j++) foo();
167#pragma omp target
168#pragma omp teams distribute private(i), reduction(+ : j), reduction(+ : q) // expected-error 4 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
169  for (int j=0; j<100; j++) foo();
170#pragma omp parallel private(k)
171#pragma omp target
172#pragma omp teams distribute reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
173  for (int j=0; j<100; j++) foo();
174#pragma omp target
175#pragma omp teams distribute reduction(+ : p), reduction(+ : p) // expected-error 2 {{variable can appear only once in OpenMP 'reduction' clause}} expected-note 2 {{previously referenced here}}
176  for (int j=0; j<100; j++) foo();
177#pragma omp target
178#pragma omp teams distribute reduction(+ : r) // expected-error 2 {{const-qualified variable cannot be reduction}}
179  for (int j=0; j<100; j++) foo();
180#pragma omp parallel shared(i)
181#pragma omp parallel reduction(min : i)
182#pragma omp target
183#pragma omp teams distribute reduction(max : j) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
184  for (int j=0; j<100; j++) foo();
185#pragma omp target
186#pragma omp teams distribute reduction(+ : fl)
187    for (int j=0; j<100; j++) foo();
188
189  return T();
190}
191
192namespace A {
193double x;
194#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
195}
196namespace B {
197using A::x;
198}
199
200int main(int argc, char **argv) {
201  const int d = 5;       // expected-note 2 {{'d' defined here}}
202  const int da[5] = {0}; // expected-note {{'da' defined here}}
203  int qa[5] = {0};
204  S4 e(4);
205  S5 g(5);
206  int i;
207  int &j = i;                  // expected-note 2 {{'j' defined here}}
208  S3 &p = k;                   // expected-note 2 {{'p' defined here}}
209  const int &r = da[i];        // expected-note {{'r' defined here}}
210  int &q = qa[i];              // expected-note {{'q' defined here}}
211  float fl;
212#pragma omp target
213#pragma omp teams distribute reduction // expected-error {{expected '(' after 'reduction'}}
214  for (int j=0; j<100; j++) foo();
215#pragma omp target
216#pragma omp teams distribute reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp teams distribute' are ignored}}
217  for (int j=0; j<100; j++) foo();
218#pragma omp target
219#pragma omp teams distribute reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
220  for (int j=0; j<100; j++) foo();
221#pragma omp target
222#pragma omp teams distribute reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
223  for (int j=0; j<100; j++) foo();
224#pragma omp target
225#pragma omp teams distribute reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
226  for (int j=0; j<100; j++) foo();
227#pragma omp target
228#pragma omp teams distribute reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
229  for (int j=0; j<100; j++) foo();
230#pragma omp target
231#pragma omp teams distribute reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
232  for (int j=0; j<100; j++) foo();
233#pragma omp target
234#pragma omp teams distribute reduction(foo : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}}
235  for (int j=0; j<100; j++) foo();
236#pragma omp target
237#pragma omp teams distribute reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
238  for (int j=0; j<100; j++) foo();
239#pragma omp target
240#pragma omp teams distribute reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name, array element or array section}}
241  for (int j=0; j<100; j++) foo();
242#pragma omp target
243#pragma omp teams distribute reduction(~ : argc) // expected-error {{expected unqualified-id}}
244  for (int j=0; j<100; j++) foo();
245#pragma omp target
246#pragma omp teams distribute reduction(&& : argc)
247  for (int j=0; j<100; j++) foo();
248#pragma omp target
249#pragma omp teams distribute reduction(^ : S1) // expected-error {{'S1' does not refer to a value}}
250  for (int j=0; j<100; j++) foo();
251#pragma omp target
252#pragma omp teams distribute 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'}}
253  for (int j=0; j<100; j++) foo();
254#pragma omp target
255#pragma omp teams distribute 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}}
256  for (int j=0; j<100; j++) foo();
257#pragma omp target
258#pragma omp teams distribute reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
259  for (int j=0; j<100; j++) foo();
260#pragma omp target
261#pragma omp teams distribute reduction(+ : ba) // expected-error {{const-qualified variable cannot be reduction}}
262  for (int j=0; j<100; j++) foo();
263#pragma omp target
264#pragma omp teams distribute reduction(* : ca) // expected-error {{const-qualified variable cannot be reduction}}
265  for (int j=0; j<100; j++) foo();
266#pragma omp target
267#pragma omp teams distribute reduction(- : da) // expected-error {{const-qualified variable cannot be reduction}}
268  for (int j=0; j<100; j++) foo();
269#pragma omp target
270#pragma omp teams distribute reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
271  for (int j=0; j<100; j++) foo();
272#pragma omp target
273#pragma omp teams distribute reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
274  for (int j=0; j<100; j++) foo();
275#pragma omp target
276#pragma omp teams distribute reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}}
277  for (int j=0; j<100; j++) foo();
278#pragma omp target
279#pragma omp teams distribute 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')}}
280  for (int j=0; j<100; j++) foo();
281#pragma omp target
282#pragma omp teams distribute reduction(+ : h, k, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be reduction}}
283  for (int j=0; j<100; j++) foo();
284#pragma omp target
285#pragma omp teams distribute reduction(+ : o) // expected-error {{no viable overloaded '='}}
286  for (int j=0; j<100; j++) foo();
287#pragma omp target
288#pragma omp teams distribute private(i), reduction(+ : j), reduction(+ : q) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
289  for (int j=0; j<100; j++) foo();
290#pragma omp parallel private(k)
291#pragma omp target
292#pragma omp teams distribute reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
293  for (int j=0; j<100; j++) foo();
294#pragma omp target
295#pragma omp teams distribute reduction(+ : p), reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'reduction' clause}} expected-note {{previously referenced here}}
296  for (int j=0; j<100; j++) foo();
297#pragma omp target
298#pragma omp teams distribute reduction(+ : r) // expected-error {{const-qualified variable cannot be reduction}}
299  for (int j=0; j<100; j++) foo();
300#pragma omp parallel shared(i)
301#pragma omp parallel reduction(min : i)
302#pragma omp target
303#pragma omp teams distribute reduction(max : j) // expected-error {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
304  for (int j=0; j<100; j++) foo();
305#pragma omp target
306#pragma omp teams distribute reduction(+ : fl)
307    for (int j=0; j<100; j++) foo();
308  static int m;
309#pragma omp target
310#pragma omp teams distribute reduction(+ : m) // OK
311  for (int j=0; j<100; j++) foo();
312
313  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}}
314}
315