1 // RUN: %clang_cc1 -std=c++11 -verify %s
3 // Note that this puts the expected lines before the directives to work around
4 // limitations in the -verify mode.
6 template <int V
, int I
>
7 void test_nontype_template_param(int *List
, int Length
) {
8 #pragma clang loop vectorize_width(V) interleave_count(I)
9 for (int i
= 0; i
< Length
; i
++) {
13 #pragma clang loop vectorize_width(V + 4) interleave_count(I + 4)
14 for (int i
= 0; i
< Length
; i
++) {
20 void test_nontype_template_vectorize(int *List
, int Length
) {
21 /* expected-error {{invalid value '-1'; must be positive}} */ #pragma clang loop vectorize_width(V)
22 for (int i
= 0; i
< Length
; i
++) {
26 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop vectorize_width(V / 2)
27 for (int i
= 0; i
< Length
; i
++) {
33 void test_nontype_template_interleave(int *List
, int Length
) {
34 /* expected-error {{invalid value '-1'; must be positive}} */ #pragma clang loop interleave_count(I)
35 for (int i
= 0; i
< Length
; i
++) {
39 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop interleave_count(2 % I)
40 for (int i
= 0; i
< Length
; i
++) {
46 void test_nontype_template_char(int *List
, int Length
) {
47 /* expected-error {{invalid argument of type 'char'; expected an integer type}} */ #pragma clang loop vectorize_width(V)
48 for (int i
= 0; i
< Length
; i
++) {
54 void test_nontype_template_bool(int *List
, int Length
) {
55 /* expected-error {{invalid argument of type 'bool'; expected an integer type}} */ #pragma clang loop vectorize_width(V)
56 for (int i
= 0; i
< Length
; i
++) {
61 template <int V
, int I
>
62 void test_nontype_template_badarg(int *List
, int Length
) {
63 /* expected-error {{use of undeclared identifier 'Vec'}} */ #pragma clang loop vectorize_width(Vec) interleave_count(I) /*
64 expected-note {{vectorize_width loop hint malformed; use vectorize_width(X, fixed) or vectorize_width(X, scalable) where X is an integer, or vectorize_width('fixed' or 'scalable')}} */
65 /* expected-error {{use of undeclared identifier 'Int'}} */ #pragma clang loop vectorize_width(V) interleave_count(Int)
66 for (int i
= 0; i
< Length
; i
++) {
72 void test_type_template_vectorize(int *List
, int Length
) {
74 /* expected-error {{invalid value '-1'; must be positive}} */ #pragma clang loop vectorize_width(Value)
75 for (int i
= 0; i
< Length
; i
++) {
79 /* expected-error {{invalid value '-1'; must be positive}} */ #pragma clang loop vectorize_width(Value, fixed)
80 for (int i
= 0; i
< Length
; i
++) {
85 void test(int *List
, int Length
) { // expected-note {{declared here}}
88 #pragma clang loop vectorize(enable)
89 #pragma clang loop interleave(enable)
90 #pragma clang loop vectorize_predicate(enable)
91 #pragma clang loop unroll(full)
92 while (i
+ 1 < Length
) {
96 #pragma clang loop vectorize_width(4)
97 #pragma clang loop interleave_count(8)
98 #pragma clang loop unroll_count(16)
103 #pragma clang loop vectorize(disable)
104 #pragma clang loop interleave(disable)
105 #pragma clang loop vectorize_predicate(disable)
106 #pragma clang loop unroll(disable)
107 while (i
- 1 < Length
) {
111 #pragma clang loop vectorize_width(4) interleave_count(8) unroll_count(16)
112 while (i
- 2 < Length
) {
116 #pragma clang loop interleave_count(16)
117 while (i
- 3 < Length
) {
121 int VList
[Length
]; // expected-warning {{variable length arrays in C++ are a Clang extension}} \
122 expected
-note
{{function parameter
'Length' with unknown value cannot be used in a constant expression
}}
123 #pragma clang loop vectorize(disable) interleave(disable) unroll(disable) vectorize_predicate(disable)
124 for (int j
: VList
) {
128 #pragma clang loop distribute(enable)
129 for (int j
: VList
) {
133 #pragma clang loop distribute(disable)
134 for (int j
: VList
) {
138 test_nontype_template_param
<4, 8>(List
, Length
);
140 /* expected-error {{expected '('}} */ #pragma clang loop vectorize
141 /* expected-error {{expected '('}} */ #pragma clang loop interleave
142 /* expected-error {{expected '('}} */ #pragma clang loop vectorize_predicate
143 /* expected-error {{expected '('}} */ #pragma clang loop unroll
144 /* expected-error {{expected '('}} */ #pragma clang loop distribute
146 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize(enable
147 /* expected-error {{expected ')'}} */ #pragma clang loop interleave(enable
148 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize_predicate(enable
149 /* expected-error {{expected ')'}} */ #pragma clang loop unroll(full
150 /* expected-error {{expected ')'}} */ #pragma clang loop distribute(enable
152 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize_width(4
153 /* expected-error {{expected ')'}} */ #pragma clang loop interleave_count(4
154 /* expected-error {{expected ')'}} */ #pragma clang loop unroll_count(4
156 /* expected-error {{missing argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop vectorize()
157 /* expected-error {{missing argument; expected an integer value}} */ #pragma clang loop interleave_count()
158 /* expected-error {{missing argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll()
159 /* expected-error {{missing argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute()
161 /* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, vectorize_predicate, or distribute}} */ #pragma clang loop
162 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword
163 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword(enable)
164 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop vectorize(enable) badkeyword(4)
165 /* expected-warning {{extra tokens at end of '#pragma clang loop'}} */ #pragma clang loop vectorize(enable) ,
166 while (i
-4 < Length
) {
170 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop vectorize_width(0)
171 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop interleave_count(0)
172 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop unroll_count(0)
174 /* expected-error {{expression is not an integral constant expression}} expected-note {{division by zero}} */ #pragma clang loop vectorize_width(10 / 0)
175 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop interleave_count(10 / 5 - 2)
176 while (i
-5 < Length
) {
180 test_nontype_template_vectorize
<4>(List
, Length
);
181 /* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_vectorize
<-1>(List
, Length
);
182 test_nontype_template_interleave
<8>(List
, Length
);
183 /* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_interleave
<-1>(List
, Length
);
185 /* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_char
<'A'>(List
, Length
); // Loop hint arg cannot be a char.
186 /* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_bool
<true>(List
, Length
); // Or a bool.
187 /* expected-note {{in instantiation of function template specialization}} */ test_type_template_vectorize
<int>(List
, Length
); // Or a template type.
189 /* expected-error {{value '3000000000' is too large}} */ #pragma clang loop vectorize_width(3000000000)
190 /* expected-error {{value '3000000000' is too large}} */ #pragma clang loop interleave_count(3000000000)
191 /* expected-error {{value '3000000000' is too large}} */ #pragma clang loop unroll_count(3000000000)
192 while (i
-6 < Length
) {
196 /* expected-warning {{extra tokens at end of '#pragma clang loop'}} */ #pragma clang loop vectorize_width(1 +) 1
197 /* expected-warning {{extra tokens at end of '#pragma clang loop'}} */ #pragma clang loop vectorize_width(1) +1
199 /* expected-error {{expected expression}} */ #pragma clang loop vectorize_width(VV +/ 2) /*
200 expected-note {{vectorize_width loop hint malformed; use vectorize_width(X, fixed) or vectorize_width(X, scalable) where X is an integer, or vectorize_width('fixed' or 'scalable')}} */
201 /* expected-error {{use of undeclared identifier 'undefined'}} */ #pragma clang loop vectorize_width(VV+undefined) /*
202 expected-note {{vectorize_width loop hint malformed; use vectorize_width(X, fixed) or vectorize_width(X, scalable) where X is an integer, or vectorize_width('fixed' or 'scalable')}} */
203 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize_width(1+(^*/2 * ()
204 /* expected-warning {{extra tokens at end of '#pragma clang loop' - ignored}} */ #pragma clang loop vectorize_width(1+(-0[0]))))))
206 /* expected-error {{use of undeclared identifier 'badvalue'}} */ #pragma clang loop vectorize_width(badvalue) /*
207 expected-note {{vectorize_width loop hint malformed; use vectorize_width(X, fixed) or vectorize_width(X, scalable) where X is an integer, or vectorize_width('fixed' or 'scalable')}} */
208 /* expected-error {{use of undeclared identifier 'badvalue'}} */ #pragma clang loop interleave_count(badvalue)
209 /* expected-error {{use of undeclared identifier 'badvalue'}} */ #pragma clang loop unroll_count(badvalue)
210 while (i
-6 < Length
) {
214 /* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop vectorize(badidentifier)
215 /* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop interleave(badidentifier)
216 /* expected-error {{invalid argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll(badidentifier)
217 /* expected-error {{invalid argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute(badidentifier)
218 while (i
-7 < Length
) {
222 // PR20069 - Loop pragma arguments that are not identifiers or numeric
223 // constants crash FE.
224 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize(()
225 /* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop interleave(*)
226 /* expected-error {{invalid argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll(=)
227 /* expected-error {{invalid argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute(+)
228 /* expected-error {{type name requires a specifier or qualifier}} expected-error {{expected expression}} */ #pragma clang loop vectorize_width(^) /* expected-note {{vectorize_width loop hint malformed; use vectorize_width(X, fixed) or vectorize_width(X, scalable) where X is an integer, or vectorize_width('fixed' or 'scalable')}} */
229 /* expected-error {{expected expression}} expected-error {{expected expression}} */ #pragma clang loop interleave_count(/)
230 /* expected-error {{expected expression}} expected-error {{expected expression}} */ #pragma clang loop unroll_count(==)
231 while (i
-8 < Length
) {
235 #pragma clang loop vectorize(enable)
236 /* expected-error {{expected a for, while, or do-while loop to follow '#pragma clang loop'}} */ int j
= Length
;
239 while (j
-1 < Length
) {
243 // FIXME: A bug in ParsedAttributes causes the order of the attributes to be
244 // processed in reverse. Consequently, the errors occur on the first of pragma
245 // of the next three tests rather than the last, and the order of the kinds
248 #pragma clang loop vectorize_width(4)
249 /* expected-error {{incompatible directives 'vectorize(disable)' and 'vectorize_width(4)'}} */ #pragma clang loop vectorize(disable)
250 #pragma clang loop interleave_count(4)
251 /* expected-error {{incompatible directives 'interleave(disable)' and 'interleave_count(4)'}} */ #pragma clang loop interleave(disable)
252 #pragma clang loop unroll_count(4)
253 /* expected-error {{incompatible directives 'unroll(disable)' and 'unroll_count(4)'}} */ #pragma clang loop unroll(disable)
254 while (i
-8 < Length
) {
258 #pragma clang loop vectorize(enable)
259 /* expected-error {{duplicate directives 'vectorize(enable)' and 'vectorize(disable)'}} */ #pragma clang loop vectorize(disable)
260 #pragma clang loop interleave(enable)
261 /* expected-error {{duplicate directives 'interleave(enable)' and 'interleave(disable)'}} */ #pragma clang loop interleave(disable)
262 #pragma clang loop vectorize_predicate(enable)
263 /* expected-error@+1 {{duplicate directives 'vectorize_predicate(enable)' and 'vectorize_predicate(disable)'}} */
264 #pragma clang loop vectorize_predicate(disable)
265 #pragma clang loop unroll(full)
266 /* expected-error {{duplicate directives 'unroll(full)' and 'unroll(disable)'}} */ #pragma clang loop unroll(disable)
267 #pragma clang loop distribute(enable)
268 /* expected-error {{duplicate directives 'distribute(enable)' and 'distribute(disable)'}} */ #pragma clang loop distribute(disable)
269 while (i
-9 < Length
) {
273 #pragma clang loop vectorize(disable)
274 /* expected-error {{incompatible directives 'vectorize(disable)' and 'vectorize_width(4)'}} */ #pragma clang loop vectorize_width(4)
275 #pragma clang loop interleave(disable)
276 /* expected-error {{incompatible directives 'interleave(disable)' and 'interleave_count(4)'}} */ #pragma clang loop interleave_count(4)
277 #pragma clang loop unroll(disable)
278 /* expected-error {{incompatible directives 'unroll(disable)' and 'unroll_count(4)'}} */ #pragma clang loop unroll_count(4)
279 while (i
-10 < Length
) {
283 #pragma clang loop vectorize_width(8)
284 /* expected-error {{duplicate directives 'vectorize_width(8)' and 'vectorize_width(4)'}} */ #pragma clang loop vectorize_width(4)
285 #pragma clang loop interleave_count(8)
286 /* expected-error {{duplicate directives 'interleave_count(8)' and 'interleave_count(4)'}} */ #pragma clang loop interleave_count(4)
287 #pragma clang loop unroll_count(8)
288 /* expected-error {{duplicate directives 'unroll_count(8)' and 'unroll_count(4)'}} */ #pragma clang loop unroll_count(4)
289 while (i
-11 < Length
) {
293 #pragma clang loop unroll(full)
294 /* expected-error {{incompatible directives 'unroll(full)' and 'unroll_count(4)'}} */ #pragma clang loop unroll_count(4)
295 while (i
-11 < Length
) {
299 #pragma clang loop interleave(enable)
300 /* expected-error {{expected statement}} */ }
303 #pragma clang loop vectorize_predicate(enable)
304 /* expected-error {{expected statement}} */ }
306 void foo(int *List
, int Length
) {
308 #pragma clang loop vectorize(enable, extra)
309 /* expected-warning {{extra tokens at end of '#pragma clang loop vectorize' - ignored}}*/ while (i
-6 < Length
) {
313 #pragma clang loop interleave(enable, extra)
314 /* expected-warning {{extra tokens at end of '#pragma clang loop interleave' - ignored}}*/ while (i
-6 < Length
) {
318 #pragma clang loop unroll(enable, extra)
319 /* expected-warning {{extra tokens at end of '#pragma clang loop unroll' - ignored}}*/ while (i
-6 < Length
) {
323 #pragma clang loop vectorize_predicate(enable, extra)
324 /* expected-warning {{extra tokens at end of '#pragma clang loop vectorize_predicate' - ignored}}*/ while (i
-6 < Length
) {
328 #pragma clang loop pipeline(disable, extra)
329 /* expected-warning {{extra tokens at end of '#pragma clang loop pipeline' - ignored}}*/ while (i
-6 < Length
) {
333 /* expected-warning {{extra tokens at end of '#pragma clang loop vectorize_width' - ignored}}*/ #pragma clang loop vectorize_width(2, scalable, extra)
334 /* expected-warning {{extra tokens at end of '#pragma clang loop interleave_count' - ignored}}*/ #pragma clang loop interleave_count(2, extra)
335 /* expected-warning {{extra tokens at end of '#pragma clang loop unroll_count' - ignored}}*/ #pragma clang loop unroll_count(2, extra)
336 /* expected-warning {{extra tokens at end of '#pragma clang loop pipeline_initiation_interval' - ignored}}*/ #pragma clang loop pipeline_initiation_interval(2, extra)
337 while (i
-6 < Length
) {