313 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 13struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}14extern S1 a;15class S2 {16 mutable int a;17 18public:19 S2() : a(0) {}20 S2(const S2 &s2) : a(s2.a) {}21 static float S2s;22 static const float S2sc;23};24const float S2::S2sc = 0;25const S2 b;26const S2 ba[5];27class S3 {28 int a;29 S3 &operator=(const S3 &s3);30 31public:32 S3() : a(0) {}33 S3(const S3 &s3) : a(s3.a) {}34};35const S3 c;36const S3 ca[5];37extern const int f;38class S4 {39 int a;40 S4();41 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}42 43public:44 S4(int v) : a(v) {}45};46class S5 {47 int a;48 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}49 50public:51 S5() : a(0) {}52 S5(int v) : a(v) {}53};54class S6 {55 int a;56 S6() : a(0) {}57 58public:59 S6(const S6 &s6) : a(s6.a) {}60 S6(int v) : a(v) {}61};62 63S3 h;64#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}65 66template <class I, class C>67int foomain(int argc, char **argv) {68 I e(4);69 C g(5);70 int i;71 int &j = i;72#pragma omp parallel73#pragma omp for simd firstprivate // expected-error {{expected '(' after 'firstprivate'}}74 for (int k = 0; k < argc; ++k)75 ++k;76#pragma omp parallel77#pragma omp for simd firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}78 for (int k = 0; k < argc; ++k)79 ++k;80#pragma omp parallel81#pragma omp for simd firstprivate() // expected-error {{expected expression}}82 for (int k = 0; k < argc; ++k)83 ++k;84#pragma omp parallel85#pragma omp for simd firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}86 for (int k = 0; k < argc; ++k)87 ++k;88#pragma omp parallel89#pragma omp for simd firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}90 for (int k = 0; k < argc; ++k)91 ++k;92#pragma omp parallel93#pragma omp for simd firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}94 for (int k = 0; k < argc; ++k)95 ++k;96#pragma omp parallel97#pragma omp 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 '('}}98 for (int k = 0; k < argc; ++k)99 ++k;100#pragma omp parallel101#pragma omp for simd firstprivate(S1) // expected-error {{'S1' does not refer to a value}}102 for (int k = 0; k < argc; ++k)103 ++k;104#pragma omp parallel105#pragma omp for simd firstprivate(a, b) // expected-error {{a firstprivate variable with incomplete type 'S1'}}106 for (int k = 0; k < argc; ++k)107 ++k;108#pragma omp parallel109#pragma omp for simd firstprivate(argv[1]) // expected-error {{expected variable name}}110 for (int k = 0; k < argc; ++k)111 ++k;112#pragma omp parallel113#pragma omp for simd firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}114 for (int k = 0; k < argc; ++k)115 ++k;116#pragma omp parallel117#pragma omp for simd firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}118 for (int k = 0; k < argc; ++k)119 ++k;120#pragma omp parallel121#pragma omp for simd linear(i)122 for (int k = 0; k < argc; ++k)123 ++k;124#pragma omp parallel125 {126 int v = 0;127 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for simd' directive into a parallel or another task region?}}128#pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}129 for (int k = 0; k < argc; ++k) {130 i = k;131 v += i;132 }133 }134#pragma omp parallel shared(i)135#pragma omp parallel private(i)136#pragma omp for simd firstprivate(j)137 for (int k = 0; k < argc; ++k)138 ++k;139#pragma omp parallel140#pragma omp for simd firstprivate(i)141 for (int k = 0; k < argc; ++k)142 ++k;143#pragma omp parallel144#pragma omp for simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}145 for (i = 0; i < argc; ++i)146 foo();147#pragma omp parallel private(i) // expected-note {{defined as private}}148#pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}149 for (i = 0; i < argc; ++i)150 foo();151#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}152#pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}153 for (int k = 0; k < argc; ++k)154 foo();155 return 0;156}157 158namespace A {159double x;160#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}161}162namespace B {163using A::x;164}165 166int main(int argc, char **argv) {167 const int d = 5;168 const int da[5] = {0};169 S4 e(4);170 S5 g(5);171 S3 m;172 S6 n(2);173 int i;174 int &j = i;175#pragma omp parallel176#pragma omp for simd firstprivate // expected-error {{expected '(' after 'firstprivate'}}177 for (i = 0; i < argc; ++i)178 foo();179#pragma omp parallel180#pragma omp for simd firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}181 for (i = 0; i < argc; ++i)182 foo();183#pragma omp parallel184#pragma omp for simd firstprivate() // expected-error {{expected expression}}185 for (i = 0; i < argc; ++i)186 foo();187#pragma omp parallel188#pragma omp for simd firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}189 for (i = 0; i < argc; ++i)190 foo();191#pragma omp parallel192#pragma omp for simd firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}193 for (i = 0; i < argc; ++i)194 foo();195#pragma omp parallel196#pragma omp for simd firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}197 for (i = 0; i < argc; ++i)198 foo();199#pragma omp parallel200#pragma omp for simd firstprivate(argc)201 for (i = 0; i < argc; ++i)202 foo();203#pragma omp parallel204#pragma omp for simd firstprivate(S1) // expected-error {{'S1' does not refer to a value}}205 for (i = 0; i < argc; ++i)206 foo();207#pragma omp parallel208#pragma omp for simd firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}209 for (i = 0; i < argc; ++i)210 foo();211#pragma omp parallel212#pragma omp for simd firstprivate(argv[1]) // expected-error {{expected variable name}}213 for (i = 0; i < argc; ++i)214 foo();215#pragma omp parallel216#pragma omp for simd firstprivate(2 * 2) // expected-error {{expected variable name}}217 for (i = 0; i < argc; ++i)218 foo();219#pragma omp parallel220#pragma omp for simd firstprivate(ba) // OK221 for (i = 0; i < argc; ++i)222 foo();223#pragma omp parallel224#pragma omp for simd firstprivate(ca) // OK225 for (i = 0; i < argc; ++i)226 foo();227#pragma omp parallel228#pragma omp for simd firstprivate(da) // OK229 for (i = 0; i < argc; ++i)230 foo();231 int xa;232#pragma omp parallel233#pragma omp for simd firstprivate(xa) // OK234 for (i = 0; i < argc; ++i)235 foo();236#pragma omp parallel237#pragma omp for simd firstprivate(S2::S2s) // OK238 for (i = 0; i < argc; ++i)239 foo();240#pragma omp parallel241#pragma omp for simd firstprivate(S2::S2sc) // OK242 for (i = 0; i < argc; ++i)243 foo();244#pragma omp parallel245#pragma omp for simd safelen(5)246 for (i = 0; i < argc; ++i)247 foo();248#pragma omp parallel249#pragma omp for simd firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}250 for (i = 0; i < argc; ++i)251 foo();252#pragma omp parallel253#pragma omp for simd firstprivate(m) // OK254 for (i = 0; i < argc; ++i)255 foo();256#pragma omp parallel257#pragma omp for simd firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}258 for (i = 0; i < argc; ++i)259 foo();260#pragma omp parallel261#pragma omp for simd firstprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}262 for (i = 0; i < argc; ++i)263 foo();264#pragma omp parallel265#pragma omp for simd private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}266 for (i = 0; i < argc; ++i)267 foo();268#pragma omp parallel269#pragma omp for simd firstprivate(i) // expected-note {{defined as firstprivate}}270 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp for simd' directive may not be firstprivate, predetermined as linear}}271 foo();272#pragma omp parallel shared(xa)273#pragma omp for simd firstprivate(xa) // OK: may be firstprivate274 for (i = 0; i < argc; ++i)275 foo();276#pragma omp parallel277#pragma omp for simd firstprivate(j)278 for (i = 0; i < argc; ++i)279 foo();280#pragma omp parallel281#pragma omp for simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}282 for (i = 0; i < argc; ++i)283 foo();284#pragma omp parallel285#pragma omp for simd lastprivate(n) firstprivate(n) // OK286 for (i = 0; i < argc; ++i)287 foo();288#pragma omp parallel289 {290 int v = 0;291 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for simd' directive into a parallel or another task region?}}292#pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}293 for (int k = 0; k < argc; ++k) {294 i = k;295 v += i;296 }297 }298#pragma omp parallel private(i) // expected-note {{defined as private}}299#pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}300 for (i = 0; i < argc; ++i)301 foo();302#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}303#pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}304 for (i = 0; i < argc; ++i)305 foo();306 static int si;307#pragma omp for simd firstprivate(si)308 for (i = 0; i < argc; ++i)309 si = i + 1;310 311 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}312}313