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