| 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 | |
| 5 | // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 150 -o - %s |
| 6 | // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++98 -ferror-limit 150 -o - %s |
| 7 | // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++11 -ferror-limit 150 -o - %s |
| 8 | |
| 9 | extern int omp_default_mem_alloc; |
| 10 | void foo() { |
| 11 | } |
| 12 | |
| 13 | bool foobool(int argc) { |
| 14 | return argc; |
| 15 | } |
| 16 | |
| 17 | void foobar(int &ref) { |
| 18 | #pragma omp parallel |
| 19 | #pragma omp sections reduction(+:ref) |
| 20 | { |
| 21 | foo(); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}} |
| 26 | extern S1 a; |
| 27 | class S2 { |
| 28 | mutable int a; |
| 29 | S2 &operator+(const S2 &arg) { return (*this); } // expected-note 3 {{implicitly declared private here}} |
| 30 | |
| 31 | public: |
| 32 | S2() : a(0) {} |
| 33 | S2(S2 &s2) : a(s2.a) {} |
| 34 | static float S2s; // expected-note 2 {{static data member is predetermined as shared}} |
| 35 | static const float S2sc; // expected-note 2 {{'S2sc' declared here}} |
| 36 | }; |
| 37 | const float S2::S2sc = 0; |
| 38 | S2 b; // expected-note 3 {{'b' defined here}} |
| 39 | const S2 ba[5]; // expected-note 2 {{'ba' defined here}} |
| 40 | class S3 { |
| 41 | int a; |
| 42 | |
| 43 | public: |
| 44 | int b; |
| 45 | S3() : a(0) {} |
| 46 | S3(const S3 &s3) : a(s3.a) {} |
| 47 | S3 operator+(const S3 &arg1) { return arg1; } |
| 48 | }; |
| 49 | int operator+(const S3 &arg1, const S3 &arg2) { return 5; } |
| 50 | S3 c; // expected-note 3 {{'c' defined here}} |
| 51 | const S3 ca[5]; // expected-note 2 {{'ca' defined here}} |
| 52 | extern const int f; // expected-note 4 {{'f' declared here}} |
| 53 | class S4 { |
| 54 | int a; |
| 55 | S4(); // expected-note {{implicitly declared private here}} |
| 56 | S4(const S4 &s4); |
| 57 | S4 &operator+(const S4 &arg) { return (*this); } |
| 58 | |
| 59 | public: |
| 60 | S4(int v) : a(v) {} |
| 61 | }; |
| 62 | S4 &operator&=(S4 &arg1, S4 &arg2) { return arg1; } |
| 63 | class S5 { |
| 64 | int a; |
| 65 | S5() : a(0) {} // expected-note {{implicitly declared private here}} |
| 66 | S5(const S5 &s5) : a(s5.a) {} |
| 67 | S5 &operator+(const S5 &arg); |
| 68 | |
| 69 | public: |
| 70 | S5(int v) : a(v) {} |
| 71 | }; |
| 72 | 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}} |
| 73 | #if __cplusplus >= 201103L // C++11 or later |
| 74 | // expected-note@-2 3 {{candidate function (the implicit move assignment operator) not viable}} |
| 75 | #endif |
| 76 | int a; |
| 77 | |
| 78 | public: |
| 79 | S6() : a(6) {} |
| 80 | operator int() { return 6; } |
| 81 | } o; |
| 82 | |
| 83 | S3 h, k; |
| 84 | #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} |
| 85 | |
| 86 | template <class T> // expected-note {{declared here}} |
| 87 | T tmain(T argc) { |
| 88 | const T d = T(); // expected-note 4 {{'d' defined here}} |
| 89 | const T da[5] = {T()}; // expected-note 2 {{'da' defined here}} |
| 90 | T qa[5] = {T()}; |
| 91 | T i; |
| 92 | T &j = i; // expected-note 4 {{'j' defined here}} |
| 93 | S3 &p = k; // expected-note 2 {{'p' defined here}} |
| 94 | const T &r = da[(int)i]; // expected-note 2 {{'r' defined here}} |
| 95 | T &q = qa[(int)i]; // expected-note 2 {{'q' defined here}} |
| 96 | T fl; |
| 97 | #pragma omp parallel |
| 98 | #pragma omp sections reduction // expected-error {{expected '(' after 'reduction'}} |
| 99 | { |
| 100 | foo(); |
| 101 | } |
| 102 | #pragma omp parallel |
| 103 | #pragma omp sections reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp sections' are ignored}} |
| 104 | { |
| 105 | foo(); |
| 106 | } |
| 107 | #pragma omp parallel |
| 108 | #pragma omp sections reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 109 | { |
| 110 | foo(); |
| 111 | } |
| 112 | #pragma omp parallel |
| 113 | #pragma omp sections reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 114 | { |
| 115 | foo(); |
| 116 | } |
| 117 | #pragma omp parallel |
| 118 | #pragma omp sections reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} |
| 119 | { |
| 120 | foo(); |
| 121 | } |
| 122 | #pragma omp parallel |
| 123 | #pragma omp sections reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} |
| 124 | { |
| 125 | foo(); |
| 126 | } |
| 127 | #pragma omp parallel |
| 128 | #pragma omp sections reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} |
| 129 | { |
| 130 | foo(); |
| 131 | } |
| 132 | #pragma omp parallel |
| 133 | #pragma omp sections reduction(& : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}} |
| 134 | { |
| 135 | foo(); |
| 136 | } |
| 137 | #pragma omp parallel |
| 138 | #pragma omp sections reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}} |
| 139 | { |
| 140 | foo(); |
| 141 | } |
| 142 | #pragma omp parallel |
| 143 | #pragma omp sections reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name, array element or array section}} |
| 144 | { |
| 145 | foo(); |
| 146 | } |
| 147 | #pragma omp parallel |
| 148 | #pragma omp sections 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'}} |
| 149 | { |
| 150 | foo(); |
| 151 | } |
| 152 | #pragma omp parallel |
| 153 | #pragma omp sections 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 '('}} |
| 154 | { |
| 155 | foo(); |
| 156 | } |
| 157 | #pragma omp parallel |
| 158 | #pragma omp sections reduction(^ : T) // expected-error {{'T' does not refer to a value}} |
| 159 | { |
| 160 | foo(); |
| 161 | } |
| 162 | #pragma omp parallel |
| 163 | #pragma omp sections 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'}} |
| 164 | { |
| 165 | foo(); |
| 166 | } |
| 167 | #pragma omp parallel |
| 168 | #pragma omp sections 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}} |
| 169 | { |
| 170 | foo(); |
| 171 | } |
| 172 | #pragma omp parallel |
| 173 | #pragma omp sections reduction(max : h.b) // expected-error {{expected variable name, array element or array section}} |
| 174 | { |
| 175 | foo(); |
| 176 | } |
| 177 | #pragma omp parallel |
| 178 | #pragma omp sections reduction(+ : ba) // expected-error {{const-qualified variable cannot be reduction}} |
| 179 | { |
| 180 | foo(); |
| 181 | } |
| 182 | #pragma omp parallel |
| 183 | #pragma omp sections reduction(* : ca) // expected-error {{const-qualified variable cannot be reduction}} |
| 184 | { |
| 185 | foo(); |
| 186 | } |
| 187 | #pragma omp parallel |
| 188 | #pragma omp sections reduction(- : da) // expected-error {{const-qualified variable cannot be reduction}} expected-error {{const-qualified variable cannot be reduction}} |
| 189 | { |
| 190 | foo(); |
| 191 | } |
| 192 | #pragma omp parallel |
| 193 | #pragma omp sections reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}} |
| 194 | { |
| 195 | foo(); |
| 196 | } |
| 197 | #pragma omp parallel |
| 198 | #pragma omp sections reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}} |
| 199 | { |
| 200 | foo(); |
| 201 | } |
| 202 | #pragma omp parallel |
| 203 | #pragma omp sections reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}} |
| 204 | { |
| 205 | foo(); |
| 206 | } |
| 207 | #pragma omp parallel |
| 208 | #pragma omp sections reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}} |
| 209 | { |
| 210 | foo(); |
| 211 | } |
| 212 | #pragma omp parallel |
| 213 | #pragma omp sections reduction(+ : o) // expected-error 2 {{no viable overloaded '='}} |
| 214 | { |
| 215 | foo(); |
| 216 | } |
| 217 | #pragma omp parallel |
| 218 | #pragma omp sections private(i), reduction(+ : j), reduction(+ : q) // expected-error 4 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} |
| 219 | { |
| 220 | foo(); |
| 221 | } |
| 222 | #pragma omp parallel private(k) |
| 223 | #pragma omp sections reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} |
| 224 | { |
| 225 | foo(); |
| 226 | } |
| 227 | #pragma omp parallel |
| 228 | #pragma omp sections reduction(+ : p), reduction(+ : p) // expected-error 2 {{variable can appear only once in OpenMP 'reduction' clause}} expected-note 2 {{previously referenced here}} |
| 229 | { |
| 230 | foo(); |
| 231 | } |
| 232 | #pragma omp parallel |
| 233 | #pragma omp sections reduction(+ : r) // expected-error 2 {{const-qualified variable cannot be reduction}} |
| 234 | { |
| 235 | foo(); |
| 236 | } |
| 237 | #pragma omp parallel shared(i) |
| 238 | #pragma omp parallel reduction(min : i) |
| 239 | #pragma omp sections reduction(max : j) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} |
| 240 | { |
| 241 | foo(); |
| 242 | } |
| 243 | #pragma omp parallel private(fl) // expected-note 2 {{defined as private}} |
| 244 | #pragma omp sections reduction(+ : fl) // expected-error 2 {{reduction variable must be shared}} |
| 245 | { |
| 246 | foo(); |
| 247 | } |
| 248 | #pragma omp parallel reduction(* : fl) // expected-note 2 {{defined as reduction}} |
| 249 | #pragma omp sections reduction(+ : fl) // expected-error 2 {{reduction variable must be shared}} |
| 250 | { |
| 251 | foo(); |
| 252 | } |
| 253 | |
| 254 | return T(); |
| 255 | } |
| 256 | |
| 257 | namespace A { |
| 258 | double x; |
| 259 | #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} |
| 260 | } |
| 261 | namespace B { |
| 262 | using A::x; |
| 263 | } |
| 264 | |
| 265 | int main(int argc, char **argv) { |
| 266 | const int d = 5; // expected-note 2 {{'d' defined here}} |
| 267 | const int da[5] = {0}; // expected-note {{'da' defined here}} |
| 268 | int qa[5] = {0}; |
| 269 | S4 e(4); |
| 270 | S5 g(5); |
| 271 | int i; |
| 272 | int &j = i; // expected-note 2 {{'j' defined here}} |
| 273 | S3 &p = k; // expected-note 2 {{'p' defined here}} |
| 274 | const int &r = da[i]; // expected-note {{'r' defined here}} |
| 275 | int &q = qa[i]; // expected-note {{'q' defined here}} |
| 276 | float fl; |
| 277 | #pragma omp parallel |
| 278 | #pragma omp sections reduction // expected-error {{expected '(' after 'reduction'}} |
| 279 | { |
| 280 | foo(); |
| 281 | } |
| 282 | #pragma omp parallel |
| 283 | #pragma omp sections reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp sections' are ignored}} |
| 284 | { |
| 285 | foo(); |
| 286 | } |
| 287 | #pragma omp parallel |
| 288 | #pragma omp sections reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 289 | { |
| 290 | foo(); |
| 291 | } |
| 292 | #pragma omp parallel |
| 293 | #pragma omp sections reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 294 | { |
| 295 | foo(); |
| 296 | } |
| 297 | #pragma omp parallel |
| 298 | #pragma omp sections reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} |
| 299 | { |
| 300 | foo(); |
| 301 | } |
| 302 | #pragma omp parallel |
| 303 | #pragma omp sections reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} |
| 304 | { |
| 305 | foo(); |
| 306 | } |
| 307 | #pragma omp parallel |
| 308 | #pragma omp sections reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} |
| 309 | { |
| 310 | foo(); |
| 311 | } |
| 312 | #pragma omp parallel |
| 313 | #pragma omp sections reduction(foo : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}} |
| 314 | { |
| 315 | foo(); |
| 316 | } |
| 317 | #pragma omp parallel |
| 318 | #pragma omp sections reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 319 | { |
| 320 | foo(); |
| 321 | } |
| 322 | #pragma omp parallel |
| 323 | #pragma omp sections reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name, array element or array section}} |
| 324 | { |
| 325 | foo(); |
| 326 | } |
| 327 | #pragma omp parallel |
| 328 | #pragma omp sections reduction(~ : argc) // expected-error {{expected unqualified-id}} |
| 329 | { |
| 330 | foo(); |
| 331 | } |
| 332 | #pragma omp parallel |
| 333 | #pragma omp sections reduction(&& : argc) |
| 334 | { |
| 335 | foo(); |
| 336 | } |
| 337 | #pragma omp parallel |
| 338 | #pragma omp sections reduction(^ : S1) // expected-error {{'S1' does not refer to a value}} |
| 339 | { |
| 340 | foo(); |
| 341 | } |
| 342 | #pragma omp parallel |
| 343 | #pragma omp sections 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'}} |
| 344 | { |
| 345 | foo(); |
| 346 | } |
| 347 | #pragma omp parallel |
| 348 | #pragma omp sections 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}} |
| 349 | { |
| 350 | foo(); |
| 351 | } |
| 352 | #pragma omp parallel |
| 353 | #pragma omp sections reduction(max : h.b) // expected-error {{expected variable name, array element or array section}} |
| 354 | { |
| 355 | foo(); |
| 356 | } |
| 357 | #pragma omp parallel |
| 358 | #pragma omp sections reduction(+ : ba) // expected-error {{const-qualified variable cannot be reduction}} |
| 359 | { |
| 360 | foo(); |
| 361 | } |
| 362 | #pragma omp parallel |
| 363 | #pragma omp sections reduction(* : ca) // expected-error {{const-qualified variable cannot be reduction}} |
| 364 | { |
| 365 | foo(); |
| 366 | } |
| 367 | #pragma omp parallel |
| 368 | #pragma omp sections reduction(- : da) // expected-error {{const-qualified variable cannot be reduction}} |
| 369 | { |
| 370 | foo(); |
| 371 | } |
| 372 | #pragma omp parallel |
| 373 | #pragma omp sections reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}} |
| 374 | { |
| 375 | foo(); |
| 376 | } |
| 377 | #pragma omp parallel |
| 378 | #pragma omp sections reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}} |
| 379 | { |
| 380 | foo(); |
| 381 | } |
| 382 | #pragma omp parallel |
| 383 | #pragma omp sections reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}} |
| 384 | { |
| 385 | foo(); |
| 386 | } |
| 387 | #pragma omp parallel |
| 388 | #pragma omp sections 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')}} |
| 389 | { |
| 390 | foo(); |
| 391 | } |
| 392 | #pragma omp parallel |
| 393 | #pragma omp sections reduction(+ : h, k, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be reduction}} |
| 394 | { |
| 395 | foo(); |
| 396 | } |
| 397 | #pragma omp parallel |
| 398 | #pragma omp sections reduction(+ : o) // expected-error {{no viable overloaded '='}} |
| 399 | { |
| 400 | foo(); |
| 401 | } |
| 402 | #pragma omp parallel |
| 403 | #pragma omp sections private(i), reduction(+ : j), reduction(+ : q) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} |
| 404 | { |
| 405 | foo(); |
| 406 | } |
| 407 | #pragma omp parallel private(k) |
| 408 | #pragma omp sections reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} |
| 409 | { |
| 410 | foo(); |
| 411 | } |
| 412 | #pragma omp parallel |
| 413 | #pragma omp sections reduction(+ : p), reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'reduction' clause}} expected-note {{previously referenced here}} |
| 414 | { |
| 415 | foo(); |
| 416 | } |
| 417 | #pragma omp parallel |
| 418 | #pragma omp sections reduction(+ : r) // expected-error {{const-qualified variable cannot be reduction}} |
| 419 | { |
| 420 | foo(); |
| 421 | } |
| 422 | #pragma omp parallel shared(i) |
| 423 | #pragma omp parallel reduction(min : i) |
| 424 | #pragma omp sections reduction(max : j) // expected-error {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} |
| 425 | { |
| 426 | foo(); |
| 427 | } |
| 428 | #pragma omp parallel private(fl) // expected-note {{defined as private}} |
| 429 | #pragma omp sections reduction(+ : fl) // expected-error {{reduction variable must be shared}} |
| 430 | { |
| 431 | foo(); |
| 432 | } |
| 433 | #pragma omp parallel reduction(* : fl) // expected-note {{defined as reduction}} |
| 434 | #pragma omp sections reduction(+ : fl) // expected-error {{reduction variable must be shared}} |
| 435 | { |
| 436 | foo(); |
| 437 | } |
| 438 | static int m; |
| 439 | #pragma omp sections reduction(+ : m) // OK |
| 440 | { |
| 441 | foo(); |
| 442 | } |
| 443 | |
| 444 | 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}} |
| 445 | } |
| 446 | |