272 lines · cpp
1// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized2 3// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized4 5extern int omp_default_mem_alloc;6void foo() {7}8 9bool foobool(int argc) {10 return argc;11}12 13void xxx(int argc) {14 int fp; // expected-note {{initialize the variable 'fp' to silence this warning}}15#pragma omp parallel for firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}}16 for (int i = 0; i < 10; ++i)17 ;18}19 20struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}21extern S1 a;22class S2 {23 mutable int a;24 25public:26 S2() : a(0) {}27 S2(const S2 &s2) : a(s2.a) {}28 static float S2s;29 static const float S2sc;30};31const float S2::S2sc = 0;32const S2 b;33const S2 ba[5];34class S3 {35 int a;36 S3 &operator=(const S3 &s3);37 38public:39 S3() : a(0) {}40 S3(const S3 &s3) : a(s3.a) {}41};42const S3 c;43const S3 ca[5];44extern const int f;45class S4 {46 int a;47 S4();48 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}49 50public:51 S4(int v) : a(v) {}52};53class S5 {54 int a;55 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}56 57public:58 S5() : a(0) {}59 S5(int v) : a(v) {}60};61class S6 {62 int a;63 S6() : a(0) {}64 65public:66 S6(const S6 &s6) : a(s6.a) {}67 S6(int v) : a(v) {}68};69 70S3 h;71#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}72 73template <class I, class C>74int foomain(int argc, char **argv) {75 I e(4);76 C g(5);77 int i, z;78 int &j = i;79#pragma omp parallel for firstprivate // expected-error {{expected '(' after 'firstprivate'}}80 for (int k = 0; k < argc; ++k)81 ++k;82#pragma omp parallel for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}83 for (int k = 0; k < argc; ++k)84 ++k;85#pragma omp parallel for firstprivate() // expected-error {{expected expression}}86 for (int k = 0; k < argc; ++k)87 ++k;88#pragma omp parallel for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}89 for (int k = 0; k < argc; ++k)90 ++k;91#pragma omp parallel for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}92 for (int k = 0; k < argc; ++k)93 ++k;94#pragma omp parallel for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}95 for (int k = 0; k < argc; ++k)96 ++k;97#pragma omp parallel for 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 '('}}98 for (int k = 0; k < argc; ++k)99 ++k;100#pragma omp parallel for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}101 for (int k = 0; k < argc; ++k)102 ++k;103#pragma omp parallel for firstprivate(z, a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}104 for (int k = 0; k < argc; ++k)105 ++k;106#pragma omp parallel for firstprivate(argv[1]) // expected-error {{expected variable name}}107 for (int k = 0; k < argc; ++k)108 ++k;109#pragma omp parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}110 for (int k = 0; k < argc; ++k)111 ++k;112#pragma omp parallel for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}113 for (int k = 0; k < argc; ++k)114 ++k;115#pragma omp parallel116 {117 int v = 0;118 int i;119#pragma omp parallel for firstprivate(i)120 for (int k = 0; k < argc; ++k) {121 i = k;122 v += i;123 }124 }125#pragma omp parallel shared(i)126#pragma omp parallel private(i)127#pragma omp parallel for firstprivate(j)128 for (int k = 0; k < argc; ++k)129 ++k;130#pragma omp parallel for firstprivate(i)131 for (int k = 0; k < argc; ++k)132 ++k;133#pragma omp parallel for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}134 for (i = 0; i < argc; ++i)135 foo();136#pragma omp parallel private(i)137#pragma omp parallel for firstprivate(i) // expected-note 2 {{defined as firstprivate}}138 for (i = 0; i < argc; ++i) // expected-error 2 {{loop iteration variable in the associated loop of 'omp parallel for' directive may not be firstprivate, predetermined as private}}139 foo();140#pragma omp parallel reduction(+ : i)141#pragma omp parallel for firstprivate(i) // expected-note 2 {{defined as firstprivate}}142 for (i = 0; i < argc; ++i) // expected-error 2 {{loop iteration variable in the associated loop of 'omp parallel for' directive may not be firstprivate, predetermined as private}}143 foo();144 return 0;145}146 147namespace A {148double x;149#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}150}151namespace B {152using A::x;153}154 155int main(int argc, char **argv) {156 const int d = 5;157 const int da[5] = {0};158 S4 e(4);159 S5 g(5);160 S3 m;161 S6 n(2);162 int i;163 int &j = i;164#pragma omp parallel for firstprivate // expected-error {{expected '(' after 'firstprivate'}}165 for (i = 0; i < argc; ++i)166 foo();167#pragma omp parallel for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}168 for (i = 0; i < argc; ++i)169 foo();170#pragma omp parallel for firstprivate() // expected-error {{expected expression}}171 for (i = 0; i < argc; ++i)172 foo();173#pragma omp parallel for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}174 for (i = 0; i < argc; ++i)175 foo();176#pragma omp parallel for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}177 for (i = 0; i < argc; ++i)178 foo();179#pragma omp parallel for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}180 for (i = 0; i < argc; ++i)181 foo();182#pragma omp parallel for firstprivate(argc)183 for (i = 0; i < argc; ++i)184 foo();185#pragma omp parallel for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}186 for (i = 0; i < argc; ++i)187 foo();188#pragma omp parallel for firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}189 for (i = 0; i < argc; ++i)190 foo();191#pragma omp parallel for firstprivate(argv[1]) // expected-error {{expected variable name}}192 for (i = 0; i < argc; ++i)193 foo();194#pragma omp parallel for firstprivate(2 * 2) // expected-error {{expected variable name}}195 for (i = 0; i < argc; ++i)196 foo();197#pragma omp parallel for firstprivate(ba) // OK198 for (i = 0; i < argc; ++i)199 foo();200#pragma omp parallel for firstprivate(ca) // OK201 for (i = 0; i < argc; ++i)202 foo();203#pragma omp parallel for firstprivate(da) // OK204 for (i = 0; i < argc; ++i)205 foo();206 int xa;207#pragma omp parallel for firstprivate(xa) // OK208 for (i = 0; i < argc; ++i)209 foo();210#pragma omp parallel for firstprivate(S2::S2s) // OK211 for (i = 0; i < argc; ++i)212 foo();213#pragma omp parallel for firstprivate(S2::S2sc) // OK214 for (i = 0; i < argc; ++i)215 foo();216#pragma omp parallel for safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp parallel for'}}217 for (i = 0; i < argc; ++i)218 foo();219#pragma omp parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}220 for (i = 0; i < argc; ++i)221 foo();222#pragma omp parallel for firstprivate(m) // OK223 for (i = 0; i < argc; ++i)224 foo();225#pragma omp parallel for firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}226 for (i = 0; i < argc; ++i)227 foo();228#pragma omp parallel for private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}229 for (i = 0; i < argc; ++i)230 foo();231#pragma omp parallel for firstprivate(i) // expected-note {{defined as firstprivate}}232 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp parallel for' directive may not be firstprivate, predetermined as private}}233 foo();234#pragma omp parallel shared(xa)235#pragma omp parallel for firstprivate(xa) // OK: may be firstprivate236 for (i = 0; i < argc; ++i)237 foo();238#pragma omp parallel for firstprivate(j)239 for (i = 0; i < argc; ++i)240 foo();241#pragma omp parallel for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}242 for (i = 0; i < argc; ++i)243 foo();244#pragma omp parallel for lastprivate(n) firstprivate(n) // OK245 for (i = 0; i < argc; ++i)246 foo();247#pragma omp parallel248 {249 int v = 0;250 int i;251#pragma omp parallel for firstprivate(i)252 for (int k = 0; k < argc; ++k) {253 i = k;254 v += i;255 }256 }257#pragma omp parallel private(i)258#pragma omp parallel for firstprivate(i) // expected-note {{defined as firstprivate}}259 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp parallel for' directive may not be firstprivate, predetermined as private}}260 foo();261#pragma omp parallel reduction(+ : i)262#pragma omp parallel for firstprivate(i) // expected-note {{defined as firstprivate}}263 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp parallel for' directive may not be firstprivate, predetermined as private}}264 foo();265 static int si;266#pragma omp parallel for firstprivate(si) // OK267 for (i = 0; i < argc; ++i)268 si = i + 1;269 270 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}271}272