1 // RUN: %clang_cc1 -std=c++11 -verify %s
2 
3 // Note that this puts the expected lines before the directives to work around
4 // limitations in the -verify mode.
5 
6 template <int V, int I>
test_nontype_template_param(int * List,int Length)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++) {
10     List[i] = i;
11   }
12 
13 #pragma clang loop vectorize_width(V + 4) interleave_count(I + 4)
14   for (int i = 0; i < Length; i++) {
15     List[i] = i;
16   }
17 }
18 
19 template <int V>
test_nontype_template_vectorize(int * List,int Length)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++) {
23     List[i] = i;
24   }
25 
26   /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop vectorize_width(V / 2)
27   for (int i = 0; i < Length; i++) {
28     List[i] += i;
29   }
30 }
31 
32 template <int I>
test_nontype_template_interleave(int * List,int Length)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++) {
36     List[i] = i;
37   }
38 
39   /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop interleave_count(2 % I)
40   for (int i = 0; i < Length; i++) {
41     List[i] = i;
42   }
43 }
44 
45 template <char V>
test_nontype_template_char(int * List,int Length)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++) {
49     List[i] = i;
50   }
51 }
52 
53 template <bool V>
test_nontype_template_bool(int * List,int Length)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++) {
57     List[i] = i;
58   }
59 }
60 
61 template <int V, int I>
test_nontype_template_badarg(int * List,int Length)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-error {{use of undeclared identifier 'Int'}} */ #pragma clang loop vectorize_width(V) interleave_count(Int)
65   for (int i = 0; i < Length; i++) {
66     List[i] = i;
67   }
68 }
69 
70 template <typename T>
test_type_template_vectorize(int * List,int Length)71 void test_type_template_vectorize(int *List, int Length) {
72   const T Value = -1;
73   /* expected-error {{invalid value '-1'; must be positive}} */ #pragma clang loop vectorize_width(Value)
74   for (int i = 0; i < Length; i++) {
75     List[i] = i;
76   }
77 }
78 
test(int * List,int Length)79 void test(int *List, int Length) {
80   int i = 0;
81 
82 #pragma clang loop vectorize(enable)
83 #pragma clang loop interleave(enable)
84 #pragma clang loop unroll(full)
85   while (i + 1 < Length) {
86     List[i] = i;
87   }
88 
89 #pragma clang loop vectorize_width(4)
90 #pragma clang loop interleave_count(8)
91 #pragma clang loop unroll_count(16)
92   while (i < Length) {
93     List[i] = i;
94   }
95 
96 #pragma clang loop vectorize(disable)
97 #pragma clang loop interleave(disable)
98 #pragma clang loop unroll(disable)
99   while (i - 1 < Length) {
100     List[i] = i;
101   }
102 
103 #pragma clang loop vectorize_width(4) interleave_count(8) unroll_count(16)
104   while (i - 2 < Length) {
105     List[i] = i;
106   }
107 
108 #pragma clang loop interleave_count(16)
109   while (i - 3 < Length) {
110     List[i] = i;
111   }
112 
113   int VList[Length];
114 #pragma clang loop vectorize(disable) interleave(disable) unroll(disable)
115   for (int j : VList) {
116     VList[j] = List[j];
117   }
118 
119   test_nontype_template_param<4, 8>(List, Length);
120 
121 /* expected-error {{expected '('}} */ #pragma clang loop vectorize
122 /* expected-error {{expected '('}} */ #pragma clang loop interleave
123 /* expected-error {{expected '('}} */ #pragma clang loop unroll
124 
125 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize(enable
126 /* expected-error {{expected ')'}} */ #pragma clang loop interleave(enable
127 /* expected-error {{expected ')'}} */ #pragma clang loop unroll(full
128 
129 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize_width(4
130 /* expected-error {{expected ')'}} */ #pragma clang loop interleave_count(4
131 /* expected-error {{expected ')'}} */ #pragma clang loop unroll_count(4
132 
133 /* expected-error {{missing argument; expected 'enable' or 'disable'}} */ #pragma clang loop vectorize()
134 /* expected-error {{missing argument; expected an integer value}} */ #pragma clang loop interleave_count()
135 /* expected-error {{missing argument; expected 'enable' or 'disable'}} */ #pragma clang loop unroll()
136 
137 /* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, or unroll_count}} */ #pragma clang loop
138 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword
139 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword(enable)
140 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop vectorize(enable) badkeyword(4)
141 /* expected-warning {{extra tokens at end of '#pragma clang loop'}} */ #pragma clang loop vectorize(enable) ,
142   while (i-4 < Length) {
143     List[i] = i;
144   }
145 
146 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop vectorize_width(0)
147 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop interleave_count(0)
148 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop unroll_count(0)
149 
150 /* expected-error {{expression is not an integral constant expression}} expected-note {{division by zero}} */ #pragma clang loop vectorize_width(10 / 0)
151 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop interleave_count(10 / 5 - 2)
152   while (i-5 < Length) {
153     List[i] = i;
154   }
155 
156 test_nontype_template_vectorize<4>(List, Length);
157 /* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_vectorize<-1>(List, Length);
158 test_nontype_template_interleave<8>(List, Length);
159 /* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_interleave<-1>(List, Length);
160 
161 /* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_char<'A'>(List, Length); // Loop hint arg cannot be a char.
162 /* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_bool<true>(List, Length);  // Or a bool.
163 /* expected-note {{in instantiation of function template specialization}} */ test_type_template_vectorize<int>(List, Length); // Or a template type.
164 
165 /* expected-error {{value '3000000000' is too large}} */ #pragma clang loop vectorize_width(3000000000)
166 /* expected-error {{value '3000000000' is too large}} */ #pragma clang loop interleave_count(3000000000)
167 /* expected-error {{value '3000000000' is too large}} */ #pragma clang loop unroll_count(3000000000)
168   while (i-6 < Length) {
169     List[i] = i;
170   }
171 
172 /* expected-warning {{extra tokens at end of '#pragma clang loop'}} */ #pragma clang loop vectorize_width(1 +) 1
173 /* expected-warning {{extra tokens at end of '#pragma clang loop'}} */ #pragma clang loop vectorize_width(1) +1
174 const int VV = 4;
175 /* expected-error {{expected expression}} */ #pragma clang loop vectorize_width(VV +/ 2)
176 /* expected-error {{use of undeclared identifier 'undefined'}} */ #pragma clang loop vectorize_width(VV+undefined)
177 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize_width(1+(^*/2 * ()
178 /* expected-warning {{extra tokens at end of '#pragma clang loop' - ignored}} */ #pragma clang loop vectorize_width(1+(-0[0]))))))
179 
180 /* expected-error {{use of undeclared identifier 'badvalue'}} */ #pragma clang loop vectorize_width(badvalue)
181 /* expected-error {{use of undeclared identifier 'badvalue'}} */ #pragma clang loop interleave_count(badvalue)
182 /* expected-error {{use of undeclared identifier 'badvalue'}} */ #pragma clang loop unroll_count(badvalue)
183   while (i-6 < Length) {
184     List[i] = i;
185   }
186 
187 /* expected-error {{invalid argument; expected 'enable' or 'disable'}} */ #pragma clang loop vectorize(badidentifier)
188 /* expected-error {{invalid argument; expected 'enable' or 'disable'}} */ #pragma clang loop interleave(badidentifier)
189 /* expected-error {{invalid argument; expected 'full' or 'disable'}} */ #pragma clang loop unroll(badidentifier)
190   while (i-7 < Length) {
191     List[i] = i;
192   }
193 
194 // PR20069 - Loop pragma arguments that are not identifiers or numeric
195 // constants crash FE.
196 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize(()
197 /* expected-error {{invalid argument; expected 'enable' or 'disable'}} */ #pragma clang loop interleave(*)
198 /* expected-error {{invalid argument; expected 'full' or 'disable'}} */ #pragma clang loop unroll(=)
199 /* expected-error {{type name requires a specifier or qualifier}} expected-error {{expected expression}} */ #pragma clang loop vectorize_width(^)
200 /* expected-error {{expected expression}} expected-error {{expected expression}} */ #pragma clang loop interleave_count(/)
201 /* expected-error {{expected expression}} expected-error {{expected expression}} */ #pragma clang loop unroll_count(==)
202   while (i-8 < Length) {
203     List[i] = i;
204   }
205 
206 #pragma clang loop vectorize(enable)
207 /* expected-error {{expected a for, while, or do-while loop to follow '#pragma clang loop'}} */ int j = Length;
208   List[0] = List[1];
209 
210   while (j-1 < Length) {
211     List[j] = j;
212   }
213 
214 // FIXME: A bug in ParsedAttributes causes the order of the attributes to be
215 // processed in reverse. Consequently, the errors occur on the first of pragma
216 // of the next three tests rather than the last, and the order of the kinds
217 // is also reversed.
218 
219 /* expected-error {{incompatible directives 'vectorize(disable)' and 'vectorize_width(4)'}} */ #pragma clang loop vectorize_width(4)
220 #pragma clang loop vectorize(disable)
221 /* expected-error {{incompatible directives 'interleave(disable)' and 'interleave_count(4)'}} */ #pragma clang loop interleave_count(4)
222 #pragma clang loop interleave(disable)
223 /* expected-error {{incompatible directives 'unroll(disable)' and 'unroll_count(4)'}} */ #pragma clang loop unroll_count(4)
224 #pragma clang loop unroll(disable)
225   while (i-8 < Length) {
226     List[i] = i;
227   }
228 
229 /* expected-error {{duplicate directives 'vectorize(disable)' and 'vectorize(enable)'}} */ #pragma clang loop vectorize(enable)
230 #pragma clang loop vectorize(disable)
231 /* expected-error {{duplicate directives 'interleave(disable)' and 'interleave(enable)'}} */ #pragma clang loop interleave(enable)
232 #pragma clang loop interleave(disable)
233 /* expected-error {{duplicate directives 'unroll(disable)' and 'unroll(full)'}} */ #pragma clang loop unroll(full)
234 #pragma clang loop unroll(disable)
235   while (i-9 < Length) {
236     List[i] = i;
237   }
238 
239 /* expected-error {{incompatible directives 'vectorize(disable)' and 'vectorize_width(4)'}} */ #pragma clang loop vectorize(disable)
240 #pragma clang loop vectorize_width(4)
241 /* expected-error {{incompatible directives 'interleave(disable)' and 'interleave_count(4)'}} */ #pragma clang loop interleave(disable)
242 #pragma clang loop interleave_count(4)
243 /* expected-error {{incompatible directives 'unroll(disable)' and 'unroll_count(4)'}} */ #pragma clang loop unroll(disable)
244 #pragma clang loop unroll_count(4)
245   while (i-10 < Length) {
246     List[i] = i;
247   }
248 
249 /* expected-error {{duplicate directives 'vectorize_width(4)' and 'vectorize_width(8)'}} */ #pragma clang loop vectorize_width(8)
250 #pragma clang loop vectorize_width(4)
251 /* expected-error {{duplicate directives 'interleave_count(4)' and 'interleave_count(8)'}} */ #pragma clang loop interleave_count(8)
252 #pragma clang loop interleave_count(4)
253 /* expected-error {{duplicate directives 'unroll_count(4)' and 'unroll_count(8)'}} */ #pragma clang loop unroll_count(8)
254 #pragma clang loop unroll_count(4)
255   while (i-11 < Length) {
256     List[i] = i;
257   }
258 
259 
260 /* expected-error {{incompatible directives 'unroll(full)' and 'unroll_count(4)'}} */ #pragma clang loop unroll(full)
261 #pragma clang loop unroll_count(4)
262   while (i-11 < Length) {
263     List[i] = i;
264   }
265 
266 #pragma clang loop interleave(enable)
267 /* expected-error {{expected statement}} */ }
268