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