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