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