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