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