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