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, lin, step; // expected-note {{initialize the variable 'lin' to silence this warning}} expected-note {{initialize the variable 'step' to silence this warning}}
17 #pragma omp taskloop simd linear(i, lin : step) // expected-warning {{variable 'lin' is uninitialized when used here}} 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 #pragma omp taskloop simd linear(B:bfoo())
40 for (int i = 0; i < 10; ++i) ;
41 // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'}}
42 #pragma omp taskloop simd linear(B::ib:B:bfoo())
43 for (int i = 0; i < 10; ++i) ;
44 // expected-error@+1 {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
45 #pragma omp taskloop simd linear(B:ib)
46 for (int i = 0; i < 10; ++i) ;
47 // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'?}}
48 #pragma omp taskloop simd linear(z:B:ib)
49 for (int i = 0; i < 10; ++i) ;
50 #pragma omp taskloop simd linear(B:B::bfoo())
51 for (int i = 0; i < 10; ++i) ;
52 #pragma omp taskloop simd linear(X::x : ::z)
53 for (int i = 0; i < 10; ++i) ;
54 #pragma omp taskloop simd linear(B,::z, X::x)
55 for (int i = 0; i < 10; ++i) ;
56 #pragma omp taskloop simd linear(::z)
57 for (int i = 0; i < 10; ++i) ;
58 // expected-error@+1 {{expected variable name}}
59 #pragma omp taskloop simd linear(B::bfoo())
60 for (int i = 0; i < 10; ++i) ;
61 #pragma omp taskloop simd linear(B::ib,B:C1+C2)
62 for (int i = 0; i < 10; ++i) ;
63 }
64
65 template<int L, class T, class N> T test_template(T* arr, N num) {
66 N i;
67 T sum = (T)0;
68 T ind2 = - num * L; // expected-note {{'ind2' defined here}}
69 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type}}
70 #pragma omp taskloop simd linear(ind2:L)
71 for (i = 0; i < num; ++i) {
72 T cur = arr[(int)ind2];
73 ind2 += L;
74 sum += cur;
75 }
76 return T();
77 }
78
test_warn()79 template<int LEN> int test_warn() {
80 int ind2 = 0;
81 // expected-warning@+1 {{zero linear step (ind2 should probably be const)}}
82 #pragma omp taskloop simd linear(ind2:LEN)
83 for (int i = 0; i < 100; i++) {
84 ind2 += LEN;
85 }
86 return ind2;
87 }
88
89 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
90 extern S1 a;
91 class S2 {
92 mutable int a;
93 public:
S2()94 S2():a(0) { }
95 };
96 const S2 b; // expected-note 2 {{'b' defined here}}
97 const S2 ba[5];
98 class S3 {
99 int a;
100 public:
S3()101 S3():a(0) { }
102 };
103 const S3 ca[5];
104 class S4 {
105 int a;
106 S4();
107 public:
S4(int v)108 S4(int v):a(v) { }
109 };
110 class S5 {
111 int a;
S5()112 S5():a(0) {}
113 public:
S5(int v)114 S5(int v):a(v) { }
115 };
116
117 S3 h;
118 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
119
foomain(I argc,C ** argv)120 template<class I, class C> int foomain(I argc, C **argv) {
121 I e(4);
122 I g(5);
123 int i, z;
124 int &j = i;
125 #pragma omp taskloop simd linear // expected-error {{expected '(' after 'linear'}}
126 for (int k = 0; k < argc; ++k) ++k;
127 #pragma omp taskloop simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
128 for (int k = 0; k < argc; ++k) ++k;
129 #pragma omp taskloop simd linear (val // expected-error {{use of undeclared identifier 'val'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
130 for (int k = 0; k < argc; ++k) ++k;
131 #pragma omp taskloop simd linear (uval( // expected-error {{expected expression}} expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}}
132 for (int k = 0; k < argc; ++k) ++k;
133 #pragma omp taskloop simd linear (ref() // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
134 for (int k = 0; k < argc; ++k) ++k;
135 #pragma omp taskloop simd linear (foo() // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
136 for (int k = 0; k < argc; ++k) ++k;
137 #pragma omp taskloop simd linear () // expected-error {{expected expression}}
138 for (int k = 0; k < argc; ++k) ++k;
139 #pragma omp taskloop simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
140 for (int k = 0; k < argc; ++k) ++k;
141 #pragma omp taskloop simd linear (val argc // expected-error {{use of undeclared identifier 'val'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
142 for (int k = 0; k < argc; ++k) ++k;
143 #pragma omp taskloop simd linear (val(argc, // expected-error {{expected expression}} expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}}
144 for (int k = 0; k < argc; ++k) ++k;
145 #pragma omp taskloop simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
146 for (int k = 0; k < argc; ++k) ++k;
147 #pragma omp 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 '('}}
148 for (int k = 0; k < argc; ++k) ++k;
149 #pragma omp taskloop simd linear (S1) // expected-error {{'S1' does not refer to a value}}
150 for (int k = 0; k < argc; ++k) ++k;
151 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
152 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
153 #pragma omp taskloop simd linear (val(a, b):B::ib)
154 for (int k = 0; k < argc; ++k) ++k;
155 #pragma omp taskloop simd linear (argv[1]) // expected-error {{expected variable name}}
156 for (int k = 0; k < argc; ++k) ++k;
157 #pragma omp 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'}}
158 for (int k = 0; k < argc; ++k) ++k;
159 #pragma omp taskloop simd linear(h, z) // expected-error {{threadprivate or thread local variable cannot be linear}}
160 for (int k = 0; k < argc; ++k) ++k;
161 #pragma omp taskloop simd linear(uval(i)) // expected-error {{variable of non-reference type 'int' can be used only with 'val' modifier, but used with 'uval'}}
162 for (int k = 0; k < argc; ++k) ++k;
163 #pragma omp parallel
164 {
165 int v = 0;
166 int i;
167 #pragma omp taskloop simd allocate(omp_thread_mem_alloc: v) linear(v:i) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'taskloop simd' directive}}
168 for (int k = 0; k < argc; ++k) { i = k; v += i; }
169 }
170 #pragma omp taskloop simd linear(ref(j))
171 for (int k = 0; k < argc; ++k) ++k;
172 #pragma omp taskloop simd linear(uval(j))
173 for (int k = 0; k < argc; ++k) ++k;
174 int v = 0;
175 #pragma omp taskloop simd linear(v:j)
176 for (int k = 0; k < argc; ++k) { ++k; v += j; }
177 #pragma omp taskloop simd linear(i)
178 for (int k = 0; k < argc; ++k) ++k;
179 return 0;
180 }
181
182 namespace A {
183 double x;
184 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
185 }
186 namespace C {
187 using A::x;
188 }
189
linear_modifiers(int argc)190 void linear_modifiers(int argc) {
191 int &f = argc;
192 #pragma omp taskloop simd linear(f)
193 for (int k = 0; k < argc; ++k) ++k;
194 #pragma omp taskloop simd linear(val(f))
195 for (int k = 0; k < argc; ++k) ++k;
196 #pragma omp taskloop simd linear(uval(f))
197 for (int k = 0; k < argc; ++k) ++k;
198 #pragma omp taskloop simd linear(ref(f))
199 for (int k = 0; k < argc; ++k) ++k;
200 #pragma omp taskloop simd linear(foo(f)) // expected-error {{expected one of 'ref', val' or 'uval' modifiers}}
201 for (int k = 0; k < argc; ++k) ++k;
202 }
203
204 int f;
main(int argc,char ** argv)205 int main(int argc, char **argv) {
206 double darr[100];
207 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
208 test_template<-4>(darr, 4);
209 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
210 test_warn<0>();
211
212 S4 e(4); // expected-note {{'e' defined here}}
213 S5 g(5); // expected-note {{'g' defined here}}
214 int i, z;
215 int &j = i;
216 #pragma omp taskloop simd linear(f) linear(f) // expected-error {{linear variable cannot be linear}} expected-note {{defined as linear}}
217 for (int k = 0; k < argc; ++k) ++k;
218 #pragma omp taskloop simd linear // expected-error {{expected '(' after 'linear'}}
219 for (int k = 0; k < argc; ++k) ++k;
220 #pragma omp taskloop simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
221 for (int k = 0; k < argc; ++k) ++k;
222 #pragma omp taskloop simd linear () // expected-error {{expected expression}}
223 for (int k = 0; k < argc; ++k) ++k;
224 #pragma omp taskloop simd linear (val // expected-error {{use of undeclared identifier 'val'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
225 for (int k = 0; k < argc; ++k) ++k;
226 #pragma omp taskloop simd linear (ref()) // expected-error {{expected expression}}
227 for (int k = 0; k < argc; ++k) ++k;
228 #pragma omp taskloop simd linear (foo()) // expected-error {{expected expression}}
229 for (int k = 0; k < argc; ++k) ++k;
230 #pragma omp taskloop simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
231 for (int k = 0; k < argc; ++k) ++k;
232 #pragma omp taskloop simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
233 for (int k = 0; k < argc; ++k) ++k;
234 #pragma omp taskloop simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
235 for (int k = 0; k < argc; ++k) ++k;
236 #pragma omp taskloop simd linear (argc, z)
237 for (int k = 0; k < argc; ++k) ++k;
238 #pragma omp taskloop simd linear (S1) // expected-error {{'S1' does not refer to a value}}
239 for (int k = 0; k < argc; ++k) ++k;
240 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
241 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
242 #pragma omp taskloop simd linear(a, b)
243 for (int k = 0; k < argc; ++k) ++k;
244 #pragma omp taskloop simd linear (argv[1]) // expected-error {{expected variable name}}
245 for (int k = 0; k < argc; ++k) ++k;
246 // expected-error@+2 {{argument of a linear clause should be of integral or pointer type, not 'S4'}}
247 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S5'}}
248 #pragma omp taskloop simd linear(val(e, g))
249 for (int k = 0; k < argc; ++k) ++k;
250 #pragma omp taskloop simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
251 for (int k = 0; k < argc; ++k) ++k;
252 #pragma omp parallel
253 {
254 int i;
255 #pragma omp taskloop simd linear(val(i))
256 for (int k = 0; k < argc; ++k) ++k;
257 #pragma omp 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'}}
258 for (int k = 0; k < argc; ++k) { ++k; i += 4; }
259 }
260 #pragma omp taskloop simd linear(ref(j))
261 for (int k = 0; k < argc; ++k) ++k;
262 #pragma omp taskloop simd linear(i)
263 for (int k = 0; k < argc; ++k) ++k;
264
265 foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
266 return 0;
267 }
268
269