blob: 6f9441bf7717a1cda2e07cd87bdc6327bfc297ce [file] [log] [blame]
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00001// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s
2// RUN: %clang_cc1 -verify -fopenmp -std=c++98 -ferror-limit 100 -o - %s
3// RUN: %clang_cc1 -verify -fopenmp -std=c++11 -ferror-limit 100 -o - %s
4
5void foo() {
6}
7
8bool foobool(int argc) {
9 return argc;
10}
11
12struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
13extern S1 a;
14class S2 {
15 mutable int a;
16 S2 &operator+(const S2 &arg) { return (*this); } // expected-note 4 {{implicitly declared private here}}
17
18public:
19 S2() : a(0) {}
20 S2(S2 &s2) : a(s2.a) {}
21 static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
22 static const float S2sc;
23};
24const float S2::S2sc = 0; // expected-note 2 {{'S2sc' defined here}}
25S2 b; // expected-note 2 {{'b' defined here}}
26const S2 ba[5]; // expected-note 2 {{'ba' defined here}}
27class S3 {
28 int a;
29
30public:
31 int b;
32 S3() : a(0) {}
33 S3(const S3 &s3) : a(s3.a) {}
34 S3 operator+(const S3 &arg1) { return arg1; }
35};
36int operator+(const S3 &arg1, const S3 &arg2) { return 5; }
37S3 c; // expected-note 2 {{'c' defined here}}
38const S3 ca[5]; // expected-note 2 {{'ca' defined here}}
39extern const int f; // expected-note 4 {{'f' declared here}}
40class S4 {
41 int a;
42 S4(); // expected-note {{implicitly declared private here}}
43 S4(const S4 &s4);
44 S4 &operator+(const S4 &arg) { return (*this); }
45
46public:
47 S4(int v) : a(v) {}
48};
49S4 &operator&=(S4 &arg1, S4 &arg2) { return arg1; }
50class S5 {
51 int a;
52 S5() : a(0) {} // expected-note {{implicitly declared private here}}
53 S5(const S5 &s5) : a(s5.a) {}
54 S5 &operator+(const S5 &arg);
55
56public:
57 S5(int v) : a(v) {}
58};
59class S6 { // expected-note 2 {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const S6' for 1st argument}}
60#if __cplusplus >= 201103L // C++11 or later
61// expected-note@-2 2 {{candidate function (the implicit move assignment operator) not viable}}
62#endif
63 int a;
64
65public:
66 S6() : a(6) {}
67 operator int() { return 6; }
68} o;
69
70S3 h, k;
71#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
72
73template <class T> // expected-note {{declared here}}
74T tmain(T argc) {
75 const T d = T(); // expected-note 4 {{'d' defined here}}
76 const T da[5] = {T()}; // expected-note 2 {{'da' defined here}}
77 T qa[5] = {T()};
78 T i;
79 T &j = i; // expected-note 4 {{'j' defined here}}
80 S3 &p = k; // expected-note 2 {{'p' defined here}}
81 const T &r = da[(int)i]; // expected-note 2 {{'r' defined here}}
82 T &q = qa[(int)i]; // expected-note 2 {{'q' defined here}}
83 T fl;
84#pragma omp target parallel reduction // expected-error {{expected '(' after 'reduction'}}
85 foo();
86#pragma omp target parallel reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp target parallel' are ignored}}
87 foo();
88#pragma omp target parallel reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
89 foo();
90#pragma omp target parallel reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
91 foo();
92#pragma omp target parallel reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
93 foo();
94#pragma omp target parallel reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
95 foo();
96#pragma omp target parallel reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
97 foo();
98#pragma omp target parallel reduction(& : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}}
99 foo();
100#pragma omp target parallel reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}}
101 foo();
102#pragma omp target parallel reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name, array element or array section}}
103 foo();
104#pragma omp target parallel reduction(foo : argc) //expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}}
105 foo();
106#pragma omp target parallel reduction(&& : argc)
107 foo();
108#pragma omp target parallel reduction(^ : T) // expected-error {{'T' does not refer to a value}}
109 foo();
110#pragma omp target parallel 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 3 {{'operator+' is a private member of 'S2'}}
111 foo();
112#pragma omp target parallel 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 3 {{const-qualified list item cannot be reduction}}
113 foo();
114#pragma omp target parallel reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
115 foo();
116#pragma omp target parallel reduction(+ : ba) // expected-error {{const-qualified list item cannot be reduction}}
117 foo();
118#pragma omp target parallel reduction(* : ca) // expected-error {{const-qualified list item cannot be reduction}}
119 foo();
120#pragma omp target parallel reduction(- : da) // expected-error {{const-qualified list item cannot be reduction}} expected-error {{const-qualified list item cannot be reduction}}
121 foo();
122#pragma omp target parallel reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
123 foo();
124#pragma omp target parallel reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
125 foo();
126#pragma omp target parallel reduction(&& : S2::S2sc) // expected-error {{const-qualified list item cannot be reduction}}
127 foo();
128#pragma omp target parallel reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}}
129 foo();
130#pragma omp target parallel reduction(+ : o) // expected-error {{no viable overloaded '='}}
131 foo();
132#pragma omp target parallel private(i), reduction(+ : j), reduction(+ : q) // expected-error 4 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
133 foo();
Arpith Chacko Jacobd8da15f2016-02-01 22:02:05 +0000134#pragma omp target parallel private(k)
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000135#pragma omp target parallel reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
136 foo();
137#pragma omp target parallel reduction(+ : p), reduction(+ : p) // expected-error 3 {{variable can appear only once in OpenMP 'reduction' clause}} expected-note 3 {{previously referenced here}}
138 foo();
139#pragma omp target parallel reduction(+ : r) // expected-error 2 {{const-qualified list item cannot be reduction}}
140 foo();
141#pragma omp target parallel shared(i)
Arpith Chacko Jacobd8da15f2016-02-01 22:02:05 +0000142#pragma omp target parallel reduction(min : i)
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000143#pragma omp target parallel reduction(max : j) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
144 foo();
145#pragma omp target parallel
146#pragma omp for private(fl)
147 for (int i = 0; i < 10; ++i)
148#pragma omp target parallel reduction(+ : fl)
149 foo();
150#pragma omp target parallel
151#pragma omp for reduction(- : fl)
152 for (int i = 0; i < 10; ++i)
153#pragma omp target parallel reduction(+ : fl)
154 foo();
155
156 return T();
157}
158
159namespace A {
160double x;
161#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
162}
163namespace B {
164using A::x;
165}
166
167int main(int argc, char **argv) {
168 const int d = 5; // expected-note 2 {{'d' defined here}}
169 const int da[5] = {0}; // expected-note {{'da' defined here}}
170 int qa[5] = {0};
171 S4 e(4);
172 S5 g(5);
173 int i;
174 int &j = i; // expected-note 2 {{'j' defined here}}
175 S3 &p = k; // expected-note 2 {{'p' defined here}}
176 const int &r = da[i]; // expected-note {{'r' defined here}}
177 int &q = qa[i]; // expected-note {{'q' defined here}}
178 float fl;
179#pragma omp target parallel reduction // expected-error {{expected '(' after 'reduction'}}
180 foo();
181#pragma omp target parallel reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp target parallel' are ignored}}
182 foo();
183#pragma omp target parallel reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
184 foo();
185#pragma omp target parallel reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
186 foo();
187#pragma omp target parallel reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
188 foo();
189#pragma omp target parallel reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
190 foo();
191#pragma omp target parallel reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
192 foo();
193#pragma omp target parallel reduction(foo : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}}
194 foo();
195#pragma omp target parallel reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
196 foo();
197#pragma omp target parallel reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name, array element or array section}}
198 foo();
199#pragma omp target parallel reduction(~ : argc) // expected-error {{expected unqualified-id}}
200 foo();
201#pragma omp target parallel reduction(&& : argc)
202 foo();
203#pragma omp target parallel reduction(^ : S1) // expected-error {{'S1' does not refer to a value}}
204 foo();
205#pragma omp target parallel 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'}}
206 foo();
207#pragma omp target parallel 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 list item cannot be reduction}}
208 foo();
209#pragma omp target parallel reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
210 foo();
211#pragma omp target parallel reduction(+ : ba) // expected-error {{const-qualified list item cannot be reduction}}
212 foo();
213#pragma omp target parallel reduction(* : ca) // expected-error {{const-qualified list item cannot be reduction}}
214 foo();
215#pragma omp target parallel reduction(- : da) // expected-error {{const-qualified list item cannot be reduction}}
216 foo();
217#pragma omp target parallel reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
218 foo();
219#pragma omp target parallel reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
220 foo();
221#pragma omp target parallel reduction(&& : S2::S2sc) // expected-error {{const-qualified list item cannot be reduction}}
222 foo();
223#pragma omp target parallel 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')}}
224 foo();
225#pragma omp target parallel reduction(+ : h, k, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be reduction}}
226 foo();
227#pragma omp target parallel reduction(+ : o) // expected-error {{no viable overloaded '='}}
228 foo();
229#pragma omp target parallel private(i), reduction(+ : j), reduction(+ : q) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
230 foo();
Arpith Chacko Jacobd8da15f2016-02-01 22:02:05 +0000231#pragma omp target parallel private(k)
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000232#pragma omp target parallel reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
233 foo();
234#pragma omp target parallel reduction(+ : p), reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'reduction' clause}} expected-note {{previously referenced here}}
235 foo();
236#pragma omp target parallel reduction(+ : r) // expected-error {{const-qualified list item cannot be reduction}}
237 foo();
238#pragma omp target parallel shared(i)
Arpith Chacko Jacobd8da15f2016-02-01 22:02:05 +0000239#pragma omp target parallel reduction(min : i)
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000240#pragma omp target parallel reduction(max : j) // expected-error {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
241 foo();
242#pragma omp target parallel
243#pragma omp for private(fl)
244 for (int i = 0; i < 10; ++i)
245#pragma omp target parallel reduction(+ : fl)
246 foo();
247#pragma omp target parallel
248#pragma omp for reduction(- : fl)
249 for (int i = 0; i < 10; ++i)
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000250#pragma omp target parallel reduction(+ : fl)
251 foo();
252 static int m;
253#pragma omp target parallel reduction(+ : m) // OK
254 m++;
255
256 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}}
257}