1 // RUN: %clang_cc1 -verify -fopenmp %s -Wno-openmp-mapping -Wuninitialized 2 3 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wno-openmp-mapping -Wuninitialized 4 5 extern int omp_default_mem_alloc; 6 void foo() { 7 } 8 9 bool foobool(int argc) { 10 return argc; 11 } 12 13 void xxx(int argc) { 14 int fp; // expected-note {{initialize the variable 'fp' to silence this warning}} 15 #pragma omp distribute parallel for simd firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}} 16 for (int i = 0; i < 10; ++i) 17 ; 18 } 19 20 struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}} 21 extern S1 a; 22 class S2 { 23 mutable int a; 24 25 public: 26 S2() : a(0) {} 27 S2(const S2 &s2) : a(s2.a) {} 28 static float S2s; 29 static const float S2sc; 30 }; 31 const float S2::S2sc = 0; 32 const S2 b; 33 const S2 ba[5]; 34 class S3 { 35 int a; 36 S3 &operator=(const S3 &s3); 37 38 public: 39 S3() : a(0) {} 40 S3(const S3 &s3) : a(s3.a) {} 41 }; 42 const S3 c; 43 const S3 ca[5]; 44 extern const int f; 45 class S4 { 46 int a; 47 S4(); 48 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}} 49 50 public: 51 S4(int v) : a(v) {} 52 }; 53 class S5 { 54 int a; 55 S5(const S5 &s5) : a(s5.a) {} // expected-note 2 {{implicitly declared private here}} 56 57 public: 58 S5() : a(0) {} 59 S5(int v) : a(v) {} 60 }; 61 class S6 { 62 int a; 63 S6() : a(0) {} // expected-note {{implicitly declared private here}} 64 65 public: 66 S6(const S6 &s6) : a(s6.a) {} 67 S6(int v) : a(v) {} 68 }; 69 70 S3 h; 71 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} 72 73 template <class I, class C> 74 int foomain(int argc, char **argv) { 75 I e(4); 76 C g(5); 77 int i, z; 78 int &j = i; 79 #pragma omp target 80 #pragma omp teams 81 #pragma omp distribute parallel for simd firstprivate // expected-error {{expected '(' after 'firstprivate'}} 82 for (int k = 0; k < argc; ++k) 83 ++k; 84 #pragma omp target 85 #pragma omp teams 86 #pragma omp distribute parallel for simd firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 87 for (int k = 0; k < argc; ++k) 88 ++k; 89 #pragma omp target 90 #pragma omp teams 91 #pragma omp distribute parallel for simd firstprivate() // expected-error {{expected expression}} 92 for (int k = 0; k < argc; ++k) 93 ++k; 94 #pragma omp target 95 #pragma omp teams 96 #pragma omp distribute parallel for simd firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 97 for (int k = 0; k < argc; ++k) 98 ++k; 99 #pragma omp target 100 #pragma omp teams 101 #pragma omp distribute parallel for simd firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 102 for (int k = 0; k < argc; ++k) 103 ++k; 104 #pragma omp target 105 #pragma omp teams 106 #pragma omp distribute parallel for simd firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 107 for (int k = 0; k < argc; ++k) 108 ++k; 109 #pragma omp target 110 #pragma omp teams 111 #pragma omp distribute parallel for simd firstprivate(argc, z) 112 for (int k = 0; k < argc; ++k) 113 ++k; 114 #pragma omp target 115 #pragma omp teams 116 #pragma omp distribute parallel for simd firstprivate(S1) // expected-error {{'S1' does not refer to a value}} 117 for (int k = 0; k < argc; ++k) 118 ++k; 119 #pragma omp target 120 #pragma omp teams 121 #pragma omp distribute parallel for simd firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} 122 for (int k = 0; k < argc; ++k) 123 ++k; 124 #pragma omp target 125 #pragma omp teams 126 #pragma omp distribute parallel for simd firstprivate(argv[1]) // expected-error {{expected variable name}} 127 for (int k = 0; k < argc; ++k) 128 ++k; 129 #pragma omp target 130 #pragma omp teams 131 #pragma omp distribute parallel for simd firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} 132 for (int k = 0; k < argc; ++k) 133 ++k; 134 #pragma omp target 135 #pragma omp teams 136 #pragma omp distribute parallel for simd firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} 137 for (int k = 0; k < argc; ++k) 138 ++k; 139 #pragma omp parallel 140 { 141 int v = 0; 142 int i; 143 #pragma omp target 144 #pragma omp teams 145 #pragma omp distribute parallel for simd firstprivate(i) 146 for (int k = 0; k < argc; ++k) { 147 i = k; 148 v += i; 149 } 150 } 151 #pragma omp parallel shared(i) 152 #pragma omp parallel private(i) 153 #pragma omp target 154 #pragma omp teams 155 #pragma omp distribute parallel for simd firstprivate(j) 156 for (int k = 0; k < argc; ++k) 157 ++k; 158 #pragma omp target 159 #pragma omp teams 160 #pragma omp distribute parallel for simd firstprivate(i) 161 for (int k = 0; k < argc; ++k) 162 ++k; 163 // expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}} 164 #pragma omp target 165 #pragma omp teams 166 #pragma omp distribute parallel for simd lastprivate(g) firstprivate(g) 167 for (i = 0; i < argc; ++i) 168 foo(); 169 #pragma omp parallel private(i) 170 #pragma omp target 171 #pragma omp teams 172 #pragma omp distribute parallel for simd firstprivate(i) // expected-note 2 {{defined as firstprivate}} 173 for (i = 0; i < argc; ++i) // expected-error 2 {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be firstprivate, predetermined as linear}} 174 foo(); 175 #pragma omp parallel reduction(+ : i) 176 #pragma omp target 177 #pragma omp teams 178 #pragma omp distribute parallel for simd firstprivate(i) // expected-note 2 {{defined as firstprivate}} 179 for (i = 0; i < argc; ++i) // expected-error 2 {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be firstprivate, predetermined as linear}} 180 foo(); 181 return 0; 182 } 183 184 namespace A { 185 double x; 186 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} 187 } 188 namespace B { 189 using A::x; 190 } 191 192 int main(int argc, char **argv) { 193 const int d = 5; 194 const int da[5] = {0}; 195 S4 e(4); 196 S5 g(5); 197 S3 m; 198 S6 n(2); 199 int i, z; 200 int &j = i; 201 #pragma omp target 202 #pragma omp teams 203 #pragma omp distribute parallel for simd firstprivate // expected-error {{expected '(' after 'firstprivate'}} 204 for (i = 0; i < argc; ++i) 205 foo(); 206 #pragma omp target 207 #pragma omp teams 208 #pragma omp distribute parallel for simd firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 209 for (i = 0; i < argc; ++i) 210 foo(); 211 #pragma omp target 212 #pragma omp teams 213 #pragma omp distribute parallel for simd firstprivate() // expected-error {{expected expression}} 214 for (i = 0; i < argc; ++i) 215 foo(); 216 #pragma omp target 217 #pragma omp teams 218 #pragma omp distribute parallel for simd firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 219 for (i = 0; i < argc; ++i) 220 foo(); 221 #pragma omp target 222 #pragma omp teams 223 #pragma omp distribute parallel for simd firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 224 for (i = 0; i < argc; ++i) 225 foo(); 226 #pragma omp target 227 #pragma omp teams 228 #pragma omp distribute parallel for simd firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 229 for (i = 0; i < argc; ++i) 230 foo(); 231 #pragma omp target 232 #pragma omp teams 233 #pragma omp distribute parallel for simd firstprivate(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 '('}} 234 for (i = 0; i < argc; ++i) 235 foo(); 236 #pragma omp target 237 #pragma omp teams 238 #pragma omp distribute parallel for simd firstprivate(S1) // expected-error {{'S1' does not refer to a value}} 239 for (i = 0; i < argc; ++i) 240 foo(); 241 #pragma omp target 242 #pragma omp teams 243 #pragma omp distribute parallel for simd firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-error {{incomplete type 'S1' where a complete type is required}} 244 for (i = 0; i < argc; ++i) 245 foo(); 246 #pragma omp target 247 #pragma omp teams 248 #pragma omp distribute parallel for simd firstprivate(argv[1]) // expected-error {{expected variable name}} 249 for (i = 0; i < argc; ++i) 250 foo(); 251 #pragma omp target 252 #pragma omp teams 253 #pragma omp distribute parallel for simd firstprivate(2 * 2) // expected-error {{expected variable name}} 254 for (i = 0; i < argc; ++i) 255 foo(); 256 #pragma omp target 257 #pragma omp teams 258 #pragma omp distribute parallel for simd firstprivate(ba, z) // OK 259 for (i = 0; i < argc; ++i) 260 foo(); 261 #pragma omp target 262 #pragma omp teams 263 #pragma omp distribute parallel for simd firstprivate(ca) // OK 264 for (i = 0; i < argc; ++i) 265 foo(); 266 #pragma omp target 267 #pragma omp teams 268 #pragma omp distribute parallel for simd firstprivate(da) // OK 269 for (i = 0; i < argc; ++i) 270 foo(); 271 int xa; 272 #pragma omp target 273 #pragma omp teams 274 #pragma omp distribute parallel for simd firstprivate(xa) // OK 275 for (i = 0; i < argc; ++i) 276 foo(); 277 #pragma omp target 278 #pragma omp teams 279 #pragma omp distribute parallel for simd firstprivate(S2::S2s) // OK 280 for (i = 0; i < argc; ++i) 281 foo(); 282 #pragma omp target 283 #pragma omp teams 284 #pragma omp distribute parallel for simd firstprivate(S2::S2sc) // OK 285 for (i = 0; i < argc; ++i) 286 foo(); 287 #pragma omp target 288 #pragma omp teams 289 #pragma omp distribute parallel for simd safelen(5) // OK 290 for (i = 0; i < argc; ++i) 291 foo(); 292 #pragma omp target 293 #pragma omp teams 294 #pragma omp distribute parallel for simd firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} 295 for (i = 0; i < argc; ++i) 296 foo(); 297 #pragma omp target 298 #pragma omp teams 299 #pragma omp distribute parallel for simd firstprivate(m) // OK 300 for (i = 0; i < argc; ++i) 301 foo(); 302 #pragma omp target 303 #pragma omp teams 304 #pragma omp distribute parallel for simd firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}} 305 for (i = 0; i < argc; ++i) 306 foo(); 307 #pragma omp target 308 #pragma omp teams 309 #pragma omp distribute parallel for simd private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}} 310 for (i = 0; i < argc; ++i) 311 foo(); 312 #pragma omp target 313 #pragma omp teams 314 #pragma omp distribute parallel for simd firstprivate(i) // expected-note {{defined as firstprivate}} 315 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be firstprivate, predetermined as linear}} 316 foo(); 317 #pragma omp parallel shared(xa) 318 #pragma omp target 319 #pragma omp teams 320 #pragma omp distribute parallel for simd firstprivate(xa) // OK: may be firstprivate 321 for (i = 0; i < argc; ++i) 322 foo(); 323 #pragma omp target 324 #pragma omp teams 325 #pragma omp distribute parallel for simd firstprivate(j) 326 for (i = 0; i < argc; ++i) 327 foo(); 328 // expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}} 329 #pragma omp target 330 #pragma omp teams 331 #pragma omp distribute parallel for simd lastprivate(g) firstprivate(g) 332 for (i = 0; i < argc; ++i) 333 foo(); 334 // expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}} 335 #pragma omp target 336 #pragma omp teams 337 #pragma omp distribute parallel for simd lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}} 338 for (i = 0; i < argc; ++i) 339 foo(); 340 #pragma omp parallel 341 { 342 int v = 0; 343 int i; 344 #pragma omp target 345 #pragma omp teams 346 #pragma omp distribute parallel for simd firstprivate(i) 347 for (int k = 0; k < argc; ++k) { 348 i = k; 349 v += i; 350 } 351 } 352 #pragma omp parallel private(i) 353 #pragma omp target 354 #pragma omp teams 355 #pragma omp distribute parallel for simd firstprivate(i) // expected-note {{defined as firstprivate}} 356 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be firstprivate, predetermined as linear}} 357 foo(); 358 #pragma omp parallel reduction(+ : i) 359 #pragma omp target 360 #pragma omp teams 361 #pragma omp distribute parallel for simd firstprivate(i) // expected-note {{defined as firstprivate}} 362 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be firstprivate, predetermined as linear}} 363 foo(); 364 static int si; 365 #pragma omp target 366 #pragma omp teams 367 #pragma omp distribute parallel for simd firstprivate(si) // OK 368 for (i = 0; i < argc; ++i) 369 si = i + 1; 370 371 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}} 372 } 373