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