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