193dc40ddSAlexey Bataev // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-version=45 -fopenmp %s -Wuninitialized
2*ff260ad0SSaiyedul Islam // RUN: %clang_cc1 -verify=expected,omp50 -fopenmp %s -Wuninitialized
360e51c48SAlexey Bataev 
493dc40ddSAlexey Bataev // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-version=45 -fopenmp-simd %s -Wuninitialized
5*ff260ad0SSaiyedul Islam // RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-simd %s -Wuninitialized
660e51c48SAlexey Bataev 
760e51c48SAlexey Bataev typedef void **omp_allocator_handle_t;
88026394dSAlexey Bataev extern const omp_allocator_handle_t omp_null_allocator;
960e51c48SAlexey Bataev extern const omp_allocator_handle_t omp_default_mem_alloc;
1060e51c48SAlexey Bataev extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
1160e51c48SAlexey Bataev extern const omp_allocator_handle_t omp_const_mem_alloc;
1260e51c48SAlexey Bataev extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
1360e51c48SAlexey Bataev extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
1460e51c48SAlexey Bataev extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
1560e51c48SAlexey Bataev extern const omp_allocator_handle_t omp_pteam_mem_alloc;
1660e51c48SAlexey Bataev extern const omp_allocator_handle_t omp_thread_mem_alloc;
1760e51c48SAlexey Bataev 
foo()1860e51c48SAlexey Bataev void foo() {
1960e51c48SAlexey Bataev }
2060e51c48SAlexey Bataev 
foobool(int argc)2160e51c48SAlexey Bataev bool foobool(int argc) {
2260e51c48SAlexey Bataev   return argc;
2360e51c48SAlexey Bataev }
2460e51c48SAlexey Bataev 
2560e51c48SAlexey Bataev struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
2660e51c48SAlexey Bataev extern S1 a;
2760e51c48SAlexey Bataev class S2 {
2860e51c48SAlexey Bataev   mutable int a;
2960e51c48SAlexey Bataev 
3060e51c48SAlexey Bataev public:
S2()3160e51c48SAlexey Bataev   S2() : a(0) {}
S2(S2 & s2)3260e51c48SAlexey Bataev   S2(S2 &s2) : a(s2.a) {}
3360e51c48SAlexey Bataev   const S2 &operator =(const S2&) const;
3460e51c48SAlexey Bataev   S2 &operator =(const S2&);
3560e51c48SAlexey Bataev   static float S2s; // expected-note {{static data member is predetermined as shared}}
3660e51c48SAlexey Bataev   static const float S2sc; // expected-note {{'S2sc' declared here}}
3760e51c48SAlexey Bataev };
3860e51c48SAlexey Bataev const float S2::S2sc = 0;
3960e51c48SAlexey Bataev const S2 b;
4060e51c48SAlexey Bataev const S2 ba[5];
4160e51c48SAlexey Bataev class S3 {
4260e51c48SAlexey Bataev   int a;
4360e51c48SAlexey Bataev   S3 &operator=(const S3 &s3); // expected-note 2 {{implicitly declared private here}}
4460e51c48SAlexey Bataev 
4560e51c48SAlexey Bataev public:
S3()4660e51c48SAlexey Bataev   S3() : a(0) {}
S3(S3 & s3)4760e51c48SAlexey Bataev   S3(S3 &s3) : a(s3.a) {}
4860e51c48SAlexey Bataev };
4960e51c48SAlexey Bataev const S3 c;         // expected-note {{'c' defined here}}
5060e51c48SAlexey Bataev const S3 ca[5];     // expected-note {{'ca' defined here}}
5160e51c48SAlexey Bataev extern const int f; // expected-note {{'f' declared here}}
5260e51c48SAlexey Bataev class S4 {
5360e51c48SAlexey Bataev   int a;
5460e51c48SAlexey Bataev   S4();             // expected-note 3 {{implicitly declared private here}}
5560e51c48SAlexey Bataev   S4(const S4 &s4);
5660e51c48SAlexey Bataev 
5760e51c48SAlexey Bataev public:
S4(int v)5860e51c48SAlexey Bataev   S4(int v) : a(v) {}
5960e51c48SAlexey Bataev };
6060e51c48SAlexey Bataev class S5 {
6160e51c48SAlexey Bataev   int a;
S5()6260e51c48SAlexey Bataev   S5() : a(0) {} // expected-note {{implicitly declared private here}}
6360e51c48SAlexey Bataev 
6460e51c48SAlexey Bataev public:
S5(const S5 & s5)6560e51c48SAlexey Bataev   S5(const S5 &s5) : a(s5.a) {}
S5(int v)6660e51c48SAlexey Bataev   S5(int v) : a(v) {}
6760e51c48SAlexey Bataev };
6860e51c48SAlexey Bataev class S6 {
6960e51c48SAlexey Bataev   int a;
S6()7060e51c48SAlexey Bataev   S6() : a(0) {}
7160e51c48SAlexey Bataev 
7260e51c48SAlexey Bataev public:
S6(const S6 & s6)7360e51c48SAlexey Bataev   S6(const S6 &s6) : a(s6.a) {}
S6(int v)7460e51c48SAlexey Bataev   S6(int v) : a(v) {}
7560e51c48SAlexey Bataev };
7660e51c48SAlexey Bataev 
7760e51c48SAlexey Bataev S3 h;
7860e51c48SAlexey Bataev #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
7960e51c48SAlexey Bataev 
8060e51c48SAlexey Bataev template <class I, class C>
foomain(int argc,char ** argv)8160e51c48SAlexey Bataev int foomain(int argc, char **argv) {
8260e51c48SAlexey Bataev   I e(4);
8360e51c48SAlexey Bataev   I g(5);
8460e51c48SAlexey Bataev   int i, z;
8560e51c48SAlexey Bataev   int &j = i;
8660e51c48SAlexey Bataev #pragma omp parallel
8760e51c48SAlexey Bataev #pragma omp master taskloop lastprivate // expected-error {{expected '(' after 'lastprivate'}}
8860e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
8960e51c48SAlexey Bataev     ++k;
9060e51c48SAlexey Bataev #pragma omp parallel
9160e51c48SAlexey Bataev #pragma omp master taskloop lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
9260e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
9360e51c48SAlexey Bataev     ++k;
9460e51c48SAlexey Bataev #pragma omp parallel
9560e51c48SAlexey Bataev #pragma omp master taskloop lastprivate() // expected-error {{expected expression}}
9660e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
9760e51c48SAlexey Bataev     ++k;
9860e51c48SAlexey Bataev #pragma omp parallel
9960e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
10060e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
10160e51c48SAlexey Bataev     ++k;
10260e51c48SAlexey Bataev #pragma omp parallel
10360e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
10460e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
10560e51c48SAlexey Bataev     ++k;
10660e51c48SAlexey Bataev #pragma omp parallel
10760e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
10860e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
10960e51c48SAlexey Bataev     ++k;
11060e51c48SAlexey Bataev #pragma omp parallel
11160e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(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 '('}}
11260e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
11360e51c48SAlexey Bataev     ++k;
11460e51c48SAlexey Bataev #pragma omp parallel
11593dc40ddSAlexey Bataev #pragma omp master taskloop lastprivate(conditional: argc) lastprivate(conditional: // expected-error 2 {{use of undeclared identifier 'conditional'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
11693dc40ddSAlexey Bataev   for (int k = 0; k < argc; ++k)
11793dc40ddSAlexey Bataev     ++k;
11893dc40ddSAlexey Bataev #pragma omp parallel
11960e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
12060e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
12160e51c48SAlexey Bataev     ++k;
12260e51c48SAlexey Bataev #pragma omp parallel
12360e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}}
12460e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
12560e51c48SAlexey Bataev     ++k;
12660e51c48SAlexey Bataev #pragma omp parallel
12760e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(argv[1]) // expected-error {{expected variable name}}
12860e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
12960e51c48SAlexey Bataev     ++k;
13060e51c48SAlexey Bataev #pragma omp parallel
13160e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(z, e, g) // expected-error 2 {{calling a private constructor of class 'S4'}}
13260e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
13360e51c48SAlexey Bataev     ++k;
13460e51c48SAlexey Bataev #pragma omp parallel
13560e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
13660e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
13760e51c48SAlexey Bataev     ++k;
13860e51c48SAlexey Bataev #pragma omp parallel
13960e51c48SAlexey Bataev   {
14060e51c48SAlexey Bataev     int v = 0;
14160e51c48SAlexey Bataev     int i;
14260e51c48SAlexey Bataev #pragma omp master taskloop allocate(omp_thread_mem_alloc: i) lastprivate(i) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'master taskloop' directive}}
14360e51c48SAlexey Bataev     for (int k = 0; k < argc; ++k) {
14460e51c48SAlexey Bataev       i = k;
14560e51c48SAlexey Bataev       v += i;
14660e51c48SAlexey Bataev     }
14760e51c48SAlexey Bataev   }
14860e51c48SAlexey Bataev #pragma omp parallel shared(i)
14960e51c48SAlexey Bataev #pragma omp parallel private(i)
15060e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(j)
15160e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
15260e51c48SAlexey Bataev     ++k;
15360e51c48SAlexey Bataev #pragma omp parallel
15460e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(i)
15560e51c48SAlexey Bataev   for (int k = 0; k < argc; ++k)
15660e51c48SAlexey Bataev     ++k;
15760e51c48SAlexey Bataev   return 0;
15860e51c48SAlexey Bataev }
15960e51c48SAlexey Bataev 
bar(S4 a[2])16060e51c48SAlexey Bataev void bar(S4 a[2]) {
16160e51c48SAlexey Bataev #pragma omp parallel
16260e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(a)
16360e51c48SAlexey Bataev   for (int i = 0; i < 2; ++i)
16460e51c48SAlexey Bataev     foo();
16560e51c48SAlexey Bataev }
16660e51c48SAlexey Bataev 
16760e51c48SAlexey Bataev namespace A {
16860e51c48SAlexey Bataev double x;
16960e51c48SAlexey Bataev #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
17060e51c48SAlexey Bataev }
17160e51c48SAlexey Bataev namespace B {
17260e51c48SAlexey Bataev using A::x;
17360e51c48SAlexey Bataev }
17460e51c48SAlexey Bataev 
main(int argc,char ** argv)17560e51c48SAlexey Bataev int main(int argc, char **argv) {
17660e51c48SAlexey Bataev   const int d = 5;       // expected-note {{'d' defined here}}
17760e51c48SAlexey Bataev   const int da[5] = {0}; // expected-note {{'da' defined here}}
17860e51c48SAlexey Bataev   S4 e(4);
17960e51c48SAlexey Bataev   S5 g(5);
18060e51c48SAlexey Bataev   S3 m;
18160e51c48SAlexey Bataev   S6 n(2);
18260e51c48SAlexey Bataev   int i, z;
18360e51c48SAlexey Bataev   int &j = i;
18460e51c48SAlexey Bataev #pragma omp parallel
18560e51c48SAlexey Bataev #pragma omp master taskloop lastprivate // expected-error {{expected '(' after 'lastprivate'}}
18660e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
18760e51c48SAlexey Bataev     foo();
18860e51c48SAlexey Bataev #pragma omp parallel
18960e51c48SAlexey Bataev #pragma omp master taskloop lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
19060e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
19160e51c48SAlexey Bataev     foo();
19260e51c48SAlexey Bataev #pragma omp parallel
19360e51c48SAlexey Bataev #pragma omp master taskloop lastprivate() // expected-error {{expected expression}}
19460e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
19560e51c48SAlexey Bataev     foo();
19660e51c48SAlexey Bataev #pragma omp parallel
19760e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
19860e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
19960e51c48SAlexey Bataev     foo();
20060e51c48SAlexey Bataev #pragma omp parallel
20160e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
20260e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
20360e51c48SAlexey Bataev     foo();
20460e51c48SAlexey Bataev #pragma omp parallel
20560e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
20660e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
20760e51c48SAlexey Bataev     foo();
20860e51c48SAlexey Bataev #pragma omp parallel
20960e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(argc, z)
21060e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
21160e51c48SAlexey Bataev     foo();
21260e51c48SAlexey Bataev #pragma omp parallel
21360e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
21460e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
21560e51c48SAlexey Bataev     foo();
21660e51c48SAlexey Bataev #pragma omp parallel
21760e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(a, b, c, d, f) // expected-error {{lastprivate variable with incomplete type 'S1'}} expected-error 1 {{const-qualified variable without mutable fields cannot be lastprivate}} expected-error 2 {{const-qualified variable cannot be lastprivate}}
21860e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
21960e51c48SAlexey Bataev     foo();
22060e51c48SAlexey Bataev #pragma omp parallel
22160e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(argv[1]) // expected-error {{expected variable name}}
22260e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
22360e51c48SAlexey Bataev     foo();
22460e51c48SAlexey Bataev #pragma omp parallel
22560e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(2 * 2) // expected-error {{expected variable name}}
22660e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
22760e51c48SAlexey Bataev     foo();
22860e51c48SAlexey Bataev #pragma omp parallel
22960e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(ba)
23060e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
23160e51c48SAlexey Bataev     foo();
23260e51c48SAlexey Bataev #pragma omp parallel
23360e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(ca) // expected-error {{const-qualified variable without mutable fields cannot be lastprivate}}
23460e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
23560e51c48SAlexey Bataev     foo();
23660e51c48SAlexey Bataev #pragma omp parallel
23760e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(da) // expected-error {{const-qualified variable cannot be lastprivate}}
23860e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
23960e51c48SAlexey Bataev     foo();
24060e51c48SAlexey Bataev   int xa;
24160e51c48SAlexey Bataev #pragma omp parallel
24260e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(xa) // OK
24360e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
24460e51c48SAlexey Bataev     foo();
24560e51c48SAlexey Bataev #pragma omp parallel
24660e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
24760e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
24860e51c48SAlexey Bataev     foo();
24960e51c48SAlexey Bataev #pragma omp parallel
25060e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(S2::S2sc) // expected-error {{const-qualified variable cannot be lastprivate}}
25160e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
25260e51c48SAlexey Bataev     foo();
25360e51c48SAlexey Bataev #pragma omp parallel
25460e51c48SAlexey Bataev #pragma omp master taskloop safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp master taskloop'}}
25560e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
25660e51c48SAlexey Bataev     foo();
25760e51c48SAlexey Bataev #pragma omp parallel
25860e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
25960e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
26060e51c48SAlexey Bataev     foo();
26160e51c48SAlexey Bataev #pragma omp parallel
26260e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
26360e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
26460e51c48SAlexey Bataev     foo();
26560e51c48SAlexey Bataev #pragma omp parallel
26660e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
26760e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
26860e51c48SAlexey Bataev     foo();
26960e51c48SAlexey Bataev #pragma omp parallel
27060e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
27160e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
27260e51c48SAlexey Bataev     foo();
27360e51c48SAlexey Bataev #pragma omp parallel
27460e51c48SAlexey Bataev #pragma omp master taskloop private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
27560e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
27660e51c48SAlexey Bataev     foo();
27760e51c48SAlexey Bataev #pragma omp parallel
27860e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(i)
27960e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
28060e51c48SAlexey Bataev     foo();
28160e51c48SAlexey Bataev #pragma omp parallel private(xa)
28260e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(xa)
28360e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
28460e51c48SAlexey Bataev     foo();
28560e51c48SAlexey Bataev #pragma omp parallel reduction(+ : xa)
28660e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(xa)
28760e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
28860e51c48SAlexey Bataev     foo();
28960e51c48SAlexey Bataev #pragma omp parallel
29060e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(j)
29160e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
29260e51c48SAlexey Bataev     foo();
29360e51c48SAlexey Bataev #pragma omp parallel
29460e51c48SAlexey Bataev #pragma omp master taskloop firstprivate(m) lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
29560e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
29660e51c48SAlexey Bataev     foo();
29760e51c48SAlexey Bataev #pragma omp parallel
29860e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(n) firstprivate(n) // OK
29960e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
30060e51c48SAlexey Bataev     foo();
30160e51c48SAlexey Bataev   static int si;
30260e51c48SAlexey Bataev #pragma omp master taskloop lastprivate(si) // OK
30360e51c48SAlexey Bataev   for (i = 0; i < argc; ++i)
30460e51c48SAlexey Bataev     si = i + 1;
30560e51c48SAlexey Bataev   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
30660e51c48SAlexey Bataev }
307