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