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