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