114a388f4SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
214a388f4SAlexey Bataev 
314a388f4SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
414a388f4SAlexey Bataev 
514a388f4SAlexey Bataev typedef void **omp_allocator_handle_t;
6*8026394dSAlexey Bataev extern const omp_allocator_handle_t omp_null_allocator;
714a388f4SAlexey Bataev extern const omp_allocator_handle_t omp_default_mem_alloc;
814a388f4SAlexey Bataev extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
914a388f4SAlexey Bataev extern const omp_allocator_handle_t omp_const_mem_alloc;
1014a388f4SAlexey Bataev extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
1114a388f4SAlexey Bataev extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
1214a388f4SAlexey Bataev extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
1314a388f4SAlexey Bataev extern const omp_allocator_handle_t omp_pteam_mem_alloc;
1414a388f4SAlexey Bataev extern const omp_allocator_handle_t omp_thread_mem_alloc;
1514a388f4SAlexey Bataev 
xxx(int argc)1614a388f4SAlexey Bataev void xxx(int argc) {
1714a388f4SAlexey Bataev   int i, lin, step; // expected-note {{initialize the variable 'lin' to silence this warning}} expected-note {{initialize the variable 'step' to silence this warning}}
1814a388f4SAlexey Bataev #pragma omp parallel master taskloop simd linear(i, lin : step) // expected-warning {{variable 'lin' is uninitialized when used here}} expected-warning {{variable 'step' is uninitialized when used here}}
1914a388f4SAlexey Bataev   for (i = 0; i < 10; ++i)
2014a388f4SAlexey Bataev     ;
2114a388f4SAlexey Bataev }
2214a388f4SAlexey Bataev 
2314a388f4SAlexey Bataev namespace X {
2414a388f4SAlexey Bataev   int x;
2514a388f4SAlexey Bataev };
2614a388f4SAlexey Bataev 
2714a388f4SAlexey Bataev struct B {
2814a388f4SAlexey Bataev   static int ib; // expected-note {{'B::ib' declared here}}
bfooB2914a388f4SAlexey Bataev   static int bfoo() { return 8; }
3014a388f4SAlexey Bataev };
3114a388f4SAlexey Bataev 
bfoo()3214a388f4SAlexey Bataev int bfoo() { return 4; }
3314a388f4SAlexey Bataev 
3414a388f4SAlexey Bataev int z;
3514a388f4SAlexey Bataev const int C1 = 1;
3614a388f4SAlexey Bataev const int C2 = 2;
test_linear_colons()3714a388f4SAlexey Bataev void test_linear_colons()
3814a388f4SAlexey Bataev {
3914a388f4SAlexey Bataev   int B = 0;
4014a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(B:bfoo())
4114a388f4SAlexey Bataev   for (int i = 0; i < 10; ++i) ;
4214a388f4SAlexey Bataev   // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'}}
4314a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(B::ib:B:bfoo())
4414a388f4SAlexey Bataev   for (int i = 0; i < 10; ++i) ;
4514a388f4SAlexey Bataev   // expected-error@+1 {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
4614a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(B:ib)
4714a388f4SAlexey Bataev   for (int i = 0; i < 10; ++i) ;
4814a388f4SAlexey Bataev   // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'?}}
4914a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(z:B:ib)
5014a388f4SAlexey Bataev   for (int i = 0; i < 10; ++i) ;
5114a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(B:B::bfoo())
5214a388f4SAlexey Bataev   for (int i = 0; i < 10; ++i) ;
5314a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(X::x : ::z)
5414a388f4SAlexey Bataev   for (int i = 0; i < 10; ++i) ;
5514a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(B,::z, X::x)
5614a388f4SAlexey Bataev   for (int i = 0; i < 10; ++i) ;
5714a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(::z)
5814a388f4SAlexey Bataev   for (int i = 0; i < 10; ++i) ;
5914a388f4SAlexey Bataev   // expected-error@+1 {{expected variable name}}
6014a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(B::bfoo())
6114a388f4SAlexey Bataev   for (int i = 0; i < 10; ++i) ;
6214a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(B::ib,B:C1+C2)
6314a388f4SAlexey Bataev   for (int i = 0; i < 10; ++i) ;
6414a388f4SAlexey Bataev }
6514a388f4SAlexey Bataev 
test_template(T * arr,N num)6614a388f4SAlexey Bataev template<int L, class T, class N> T test_template(T* arr, N num) {
6714a388f4SAlexey Bataev   N i;
6814a388f4SAlexey Bataev   T sum = (T)0;
6914a388f4SAlexey Bataev   T ind2 = - num * L; // expected-note {{'ind2' defined here}}
7014a388f4SAlexey Bataev   // expected-error@+1 {{argument of a linear clause should be of integral or pointer type}}
7114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd linear(ind2:L)
7214a388f4SAlexey Bataev   for (i = 0; i < num; ++i) {
7314a388f4SAlexey Bataev     T cur = arr[(int)ind2];
7414a388f4SAlexey Bataev     ind2 += L;
7514a388f4SAlexey Bataev     sum += cur;
7614a388f4SAlexey Bataev   }
7714a388f4SAlexey Bataev   return T();
7814a388f4SAlexey Bataev }
7914a388f4SAlexey Bataev 
test_warn()8014a388f4SAlexey Bataev template<int LEN> int test_warn() {
8114a388f4SAlexey Bataev   int ind2 = 0;
8214a388f4SAlexey Bataev   // expected-warning@+1 {{zero linear step (ind2 should probably be const)}}
8314a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(ind2:LEN)
8414a388f4SAlexey Bataev   for (int i = 0; i < 100; i++) {
8514a388f4SAlexey Bataev     ind2 += LEN;
8614a388f4SAlexey Bataev   }
8714a388f4SAlexey Bataev   return ind2;
8814a388f4SAlexey Bataev }
8914a388f4SAlexey Bataev 
9014a388f4SAlexey Bataev struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
9114a388f4SAlexey Bataev extern S1 a;
9214a388f4SAlexey Bataev class S2 {
9314a388f4SAlexey Bataev   mutable int a;
9414a388f4SAlexey Bataev public:
S2()9514a388f4SAlexey Bataev   S2():a(0) { }
9614a388f4SAlexey Bataev };
9714a388f4SAlexey Bataev const S2 b; // expected-note 2 {{'b' defined here}}
9814a388f4SAlexey Bataev const S2 ba[5];
9914a388f4SAlexey Bataev class S3 {
10014a388f4SAlexey Bataev   int a;
10114a388f4SAlexey Bataev public:
S3()10214a388f4SAlexey Bataev   S3():a(0) { }
10314a388f4SAlexey Bataev };
10414a388f4SAlexey Bataev const S3 ca[5];
10514a388f4SAlexey Bataev class S4 {
10614a388f4SAlexey Bataev   int a;
10714a388f4SAlexey Bataev   S4();
10814a388f4SAlexey Bataev public:
S4(int v)10914a388f4SAlexey Bataev   S4(int v):a(v) { }
11014a388f4SAlexey Bataev };
11114a388f4SAlexey Bataev class S5 {
11214a388f4SAlexey Bataev   int a;
S5()11314a388f4SAlexey Bataev   S5():a(0) {}
11414a388f4SAlexey Bataev public:
S5(int v)11514a388f4SAlexey Bataev   S5(int v):a(v) { }
11614a388f4SAlexey Bataev };
11714a388f4SAlexey Bataev 
11814a388f4SAlexey Bataev S3 h;
11914a388f4SAlexey Bataev #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
12014a388f4SAlexey Bataev 
foomain(I argc,C ** argv)12114a388f4SAlexey Bataev template<class I, class C> int foomain(I argc, C **argv) {
12214a388f4SAlexey Bataev   I e(4);
12314a388f4SAlexey Bataev   I g(5);
12414a388f4SAlexey Bataev   int i, z;
12514a388f4SAlexey Bataev   int &j = i;
12614a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear // expected-error {{expected '(' after 'linear'}}
12714a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
12814a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
12914a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
13014a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (val // expected-error {{use of undeclared identifier 'val'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
13114a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
13214a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (uval( // expected-error {{expected expression}} expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}}
13314a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
13414a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (ref() // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
13514a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
13614a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (foo() // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
13714a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
13814a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear () // expected-error {{expected expression}}
13914a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
14014a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
14114a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
14214a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (val argc // expected-error {{use of undeclared identifier 'val'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
14314a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
14414a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (val(argc, // expected-error {{expected expression}} expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}}
14514a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
14614a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
14714a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
14814a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (argc : 5) 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 '('}}
14914a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
15014a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (S1) // expected-error {{'S1' does not refer to a value}}
15114a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
15214a388f4SAlexey Bataev   // expected-error@+2 {{linear variable with incomplete type 'S1'}}
15314a388f4SAlexey Bataev   // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
15414a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (val(a, b):B::ib)
15514a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
15614a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (argv[1]) // expected-error {{expected variable name}}
15714a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
15814a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(ref(e, g)) // expected-error 2 {{variable of non-reference type 'int' can be used only with 'val' modifier, but used with 'ref'}}
15914a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
16014a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(h, z) // expected-error {{threadprivate or thread local variable cannot be linear}}
16114a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
16214a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(uval(i)) // expected-error {{variable of non-reference type 'int' can be used only with 'val' modifier, but used with 'uval'}}
16314a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
16414a388f4SAlexey Bataev   #pragma omp parallel
16514a388f4SAlexey Bataev   {
16614a388f4SAlexey Bataev     int v = 0;
16714a388f4SAlexey Bataev     int i;
16814a388f4SAlexey Bataev     #pragma omp parallel master taskloop simd allocate(omp_thread_mem_alloc: v) linear(v:i) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'parallel master taskloop simd' directive}}
16914a388f4SAlexey Bataev     for (int k = 0; k < argc; ++k) { i = k; v += i; }
17014a388f4SAlexey Bataev   }
17114a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(ref(j))
17214a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
17314a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(uval(j))
17414a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
17514a388f4SAlexey Bataev   int v = 0;
17614a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(v:j)
17714a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) { ++k; v += j; }
17814a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(i)
17914a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
18014a388f4SAlexey Bataev   return 0;
18114a388f4SAlexey Bataev }
18214a388f4SAlexey Bataev 
18314a388f4SAlexey Bataev namespace A {
18414a388f4SAlexey Bataev double x;
18514a388f4SAlexey Bataev #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
18614a388f4SAlexey Bataev }
18714a388f4SAlexey Bataev namespace C {
18814a388f4SAlexey Bataev using A::x;
18914a388f4SAlexey Bataev }
19014a388f4SAlexey Bataev 
linear_modifiers(int argc)19114a388f4SAlexey Bataev void linear_modifiers(int argc) {
19214a388f4SAlexey Bataev   int &f = argc;
19314a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(f)
19414a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
19514a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(val(f))
19614a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
19714a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(uval(f))
19814a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
19914a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(ref(f))
20014a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
20114a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(foo(f)) // expected-error {{expected one of 'ref', val' or 'uval' modifiers}}
20214a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
20314a388f4SAlexey Bataev }
20414a388f4SAlexey Bataev 
20514a388f4SAlexey Bataev int f;
main(int argc,char ** argv)20614a388f4SAlexey Bataev int main(int argc, char **argv) {
20714a388f4SAlexey Bataev   double darr[100];
20814a388f4SAlexey Bataev   // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
20914a388f4SAlexey Bataev   test_template<-4>(darr, 4);
21014a388f4SAlexey Bataev   // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
21114a388f4SAlexey Bataev   test_warn<0>();
21214a388f4SAlexey Bataev 
21314a388f4SAlexey Bataev   S4 e(4); // expected-note {{'e' defined here}}
21414a388f4SAlexey Bataev   S5 g(5); // expected-note {{'g' defined here}}
21514a388f4SAlexey Bataev   int i, z;
21614a388f4SAlexey Bataev   int &j = i;
21714a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(f) linear(f) // expected-error {{linear variable cannot be linear}} expected-note {{defined as linear}}
21814a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
21914a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear // expected-error {{expected '(' after 'linear'}}
22014a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
22114a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
22214a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
22314a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear () // expected-error {{expected expression}}
22414a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
22514a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (val // expected-error {{use of undeclared identifier 'val'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
22614a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
22714a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (ref()) // expected-error {{expected expression}}
22814a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
22914a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (foo()) // expected-error {{expected expression}}
23014a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
23114a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
23214a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
23314a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
23414a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
23514a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
23614a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
23714a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (argc, z)
23814a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
23914a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (S1) // expected-error {{'S1' does not refer to a value}}
24014a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
24114a388f4SAlexey Bataev   // expected-error@+2 {{linear variable with incomplete type 'S1'}}
24214a388f4SAlexey Bataev   // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
24314a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(a, b)
24414a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
24514a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear (argv[1]) // expected-error {{expected variable name}}
24614a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
24714a388f4SAlexey Bataev   // expected-error@+2 {{argument of a linear clause should be of integral or pointer type, not 'S4'}}
24814a388f4SAlexey Bataev   // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S5'}}
24914a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(val(e, g))
25014a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
25114a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
25214a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
25314a388f4SAlexey Bataev   #pragma omp parallel
25414a388f4SAlexey Bataev   {
25514a388f4SAlexey Bataev     int i;
25614a388f4SAlexey Bataev     #pragma omp parallel master taskloop simd linear(val(i))
25714a388f4SAlexey Bataev     for (int k = 0; k < argc; ++k) ++k;
25814a388f4SAlexey Bataev     #pragma omp parallel master taskloop simd linear(uval(i) : 4) // expected-error {{variable of non-reference type 'int' can be used only with 'val' modifier, but used with 'uval'}}
25914a388f4SAlexey Bataev     for (int k = 0; k < argc; ++k) { ++k; i += 4; }
26014a388f4SAlexey Bataev   }
26114a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(ref(j))
26214a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
26314a388f4SAlexey Bataev   #pragma omp parallel master taskloop simd linear(i)
26414a388f4SAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
26514a388f4SAlexey Bataev 
26614a388f4SAlexey Bataev   foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
26714a388f4SAlexey Bataev   return 0;
26814a388f4SAlexey Bataev }
26914a388f4SAlexey Bataev 
270