1 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
2 
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
4 
5 extern int omp_default_mem_alloc;
6 
xxx(int argc)7 void xxx(int argc) {
8   int i, lin, step; // expected-note {{initialize the variable 'lin' to silence this warning}} expected-note {{initialize the variable 'step' to silence this warning}}
9 #pragma omp for linear(lin : step) // expected-warning {{variable 'lin' is uninitialized when used here}} expected-warning {{variable 'step' is uninitialized when used here}}
10   for (i = 0; i < 10; ++i)
11     ;
12 }
13 
14 namespace X {
15   int x;
16 };
17 
18 struct B {
19   static int ib; // expected-note {{'B::ib' declared here}}
bfooB20   static int bfoo() { return 8; }
21 };
22 
bfoo()23 int bfoo() { return 4; }
24 
25 int z;
26 const int C1 = 1;
27 const int C2 = 2;
test_linear_colons()28 void test_linear_colons()
29 {
30   int B = 0;
31   #pragma omp for linear(B:bfoo())
32   for (int i = 0; i < 10; ++i) ;
33   // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'}}
34   #pragma omp for linear(B::ib:B:bfoo())
35   for (int i = 0; i < 10; ++i) ;
36   // expected-error@+1 {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
37   #pragma omp for linear(B:ib)
38   for (int i = 0; i < 10; ++i) ;
39   // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'?}}
40   #pragma omp for linear(z:B:ib)
41   for (int i = 0; i < 10; ++i) ;
42   #pragma omp for linear(B:B::bfoo())
43   for (int i = 0; i < 10; ++i) ;
44   #pragma omp for linear(X::x : ::z)
45   for (int i = 0; i < 10; ++i) ;
46   #pragma omp for linear(B,::z, X::x)
47   for (int i = 0; i < 10; ++i) ;
48   #pragma omp for linear(::z)
49   for (int i = 0; i < 10; ++i) ;
50   // expected-error@+1 {{expected variable name}}
51   #pragma omp for linear(B::bfoo())
52   for (int i = 0; i < 10; ++i) ;
53   #pragma omp for linear(B::ib,B:C1+C2)
54   for (int i = 0; i < 10; ++i) ;
55 }
56 
57 template<int L, class T, class N> T test_template(T* arr, N num) {
58   N i;
59   T sum = (T)0;
60   T ind2 = - num * L; // expected-note {{'ind2' defined here}}
61   // expected-error@+1 {{argument of a linear clause should be of integral or pointer type}}
62 #pragma omp for linear(ind2:L)
63   for (i = 0; i < num; ++i) {
64     T cur = arr[(int)ind2];
65     ind2 += L;
66     sum += cur;
67   }
68   return T();
69 }
70 
test_warn()71 template<int LEN> int test_warn() {
72   int ind2 = 0;
73   // expected-warning@+1 {{zero linear step (ind2 should probably be const)}}
74   #pragma omp for linear(ind2:LEN)
75   for (int i = 0; i < 100; i++) {
76     ind2 += LEN;
77   }
78   return ind2;
79 }
80 
81 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
82 extern S1 a;
83 class S2 {
84   mutable int a;
85 public:
S2()86   S2():a(0) { }
87 };
88 const S2 b; // expected-note 2 {{'b' defined here}}
89 const S2 ba[5];
90 class S3 {
91   int a;
92 public:
S3()93   S3():a(0) { }
94 };
95 const S3 ca[5];
96 class S4 {
97   int a;
98   S4();
99 public:
S4(int v)100   S4(int v):a(v) { }
101 };
102 class S5 {
103   int a;
S5()104   S5():a(0) {}
105 public:
S5(int v)106   S5(int v):a(v) { }
107 };
108 
109 S3 h;
110 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
111 
foomain(I argc,C ** argv)112 template<class I, class C> int foomain(I argc, C **argv) {
113   I e(4);
114   I g(5);
115   int i, k;
116   int &j = i;
117   #pragma omp for linear // expected-error {{expected '(' after 'linear'}}
118   for (int k = 0; k < argc; ++k) ++k;
119   #pragma omp for linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
120   for (int k = 0; k < argc; ++k) ++k;
121   #pragma omp for linear () // expected-error {{expected expression}}
122   for (int k = 0; k < argc; ++k) ++k;
123   #pragma omp for linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
124   for (int k = 0; k < argc; ++k) ++k;
125   #pragma omp for linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
126   for (int k = 0; k < argc; ++k) ++k;
127   #pragma omp for linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
128   for (int k = 0; k < argc; ++k) ++k;
129   #pragma omp for 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 '('}}
130   for (int k = 0; k < argc; ++k) ++k;
131   #pragma omp for linear (S1) // expected-error {{'S1' does not refer to a value}}
132   for (int k = 0; k < argc; ++k) ++k;
133   // expected-error@+2 {{linear variable with incomplete type 'S1'}}
134   // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
135   #pragma omp for linear (a, b:B::ib)
136   for (int k = 0; k < argc; ++k) ++k;
137   #pragma omp for linear (argv[1]) // expected-error {{expected variable name}}
138   for (int k = 0; k < argc; ++k) ++k;
139   #pragma omp for linear(e, g, k)
140   for (int k = 0; k < argc; ++k) ++k;
141   #pragma omp for linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
142   for (int k = 0; k < argc; ++k) ++k;
143   #pragma omp for linear(i)
144   for (int k = 0; k < argc; ++k) ++k;
145   #pragma omp parallel
146   {
147     int v = 0;
148     int i;
149     #pragma omp for linear(v:i)
150     for (int k = 0; k < argc; ++k) { i = k; v += i; }
151   }
152   #pragma omp for linear(j)
153   for (int k = 0; k < argc; ++k) ++k;
154   int v = 0;
155   #pragma omp for linear(v:j)
156   for (int k = 0; k < argc; ++k) { ++k; v += j; }
157   #pragma omp for linear(i)
158   for (int k = 0; k < argc; ++k) ++k;
159   #pragma omp for linear(i) ordered(1) // expected-error {{'linear' clause cannot be specified along with 'ordered' clause with a parameter}}
160   for (int k = 0; k < argc; ++k) ++k;
161   return 0;
162 }
163 
164 namespace A {
165 double x;
166 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
167 }
168 namespace C {
169 using A::x;
170 }
171 
main(int argc,char ** argv)172 int main(int argc, char **argv) {
173   double darr[100];
174   // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
175   test_template<-4>(darr, 4);
176   // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
177   test_warn<0>();
178 
179   S4 e(4); // expected-note {{'e' defined here}}
180   S5 g(5); // expected-note {{'g' defined here}}
181   int i, k;
182   int &j = i;
183   #pragma omp for linear // expected-error {{expected '(' after 'linear'}}
184   for (int k = 0; k < argc; ++k) ++k;
185   #pragma omp for linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
186   for (int k = 0; k < argc; ++k) ++k;
187   #pragma omp for linear () // expected-error {{expected expression}}
188   for (int k = 0; k < argc; ++k) ++k;
189   #pragma omp for linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
190   for (int k = 0; k < argc; ++k) ++k;
191   #pragma omp for linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
192   for (int k = 0; k < argc; ++k) ++k;
193   #pragma omp for linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
194   for (int k = 0; k < argc; ++k) ++k;
195   #pragma omp for linear (argc)
196   for (int k = 0; k < argc; ++k) ++k;
197   #pragma omp for linear (S1) // expected-error {{'S1' does not refer to a value}}
198   for (int k = 0; k < argc; ++k) ++k;
199   // expected-error@+2 {{linear variable with incomplete type 'S1'}}
200   // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
201   #pragma omp for linear(a, b, k)
202   for (int k = 0; k < argc; ++k) ++k;
203   #pragma omp for linear (argv[1]) // expected-error {{expected variable name}}
204   for (int k = 0; k < argc; ++k) ++k;
205   // expected-error@+2 {{argument of a linear clause should be of integral or pointer type, not 'S4'}}
206   // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S5'}}
207   #pragma omp for linear(e, g)
208   for (int k = 0; k < argc; ++k) ++k;
209   #pragma omp for linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
210   for (int k = 0; k < argc; ++k) ++k;
211   #pragma omp parallel
212   {
213     int i;
214     #pragma omp for linear(i)
215     for (int k = 0; k < argc; ++k) ++k;
216     #pragma omp for linear(i : 4)
217     for (int k = 0; k < argc; ++k) { ++k; i += 4; }
218   }
219   #pragma omp for linear(j)
220   for (int k = 0; k < argc; ++k) ++k;
221   #pragma omp for linear(i)
222   for (int k = 0; k < argc; ++k) ++k;
223   #pragma omp for linear(i) ordered(1) // expected-error {{'linear' clause cannot be specified along with 'ordered' clause with a parameter}}
224   for (int k = 0; k < argc; ++k) ++k;
225 
226   foomain<int,char>(argc,argv); // expected-note {{n instantiation of function template specialization 'foomain<int, char>' requested here}}
227   return 0;
228 }
229 
230