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> 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> 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> 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> 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> 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> 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> 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 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 #pragma clang loop distribute(enable) 120 for (int j : VList) { 121 VList[j] = List[j]; 122 } 123 124 #pragma clang loop distribute(disable) 125 for (int j : VList) { 126 VList[j] = List[j]; 127 } 128 129 test_nontype_template_param<4, 8>(List, Length); 130 131 /* expected-error {{expected '('}} */ #pragma clang loop vectorize 132 /* expected-error {{expected '('}} */ #pragma clang loop interleave 133 /* expected-error {{expected '('}} */ #pragma clang loop unroll 134 /* expected-error {{expected '('}} */ #pragma clang loop distribute 135 136 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize(enable 137 /* expected-error {{expected ')'}} */ #pragma clang loop interleave(enable 138 /* expected-error {{expected ')'}} */ #pragma clang loop unroll(full 139 /* expected-error {{expected ')'}} */ #pragma clang loop distribute(enable 140 141 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize_width(4 142 /* expected-error {{expected ')'}} */ #pragma clang loop interleave_count(4 143 /* expected-error {{expected ')'}} */ #pragma clang loop unroll_count(4 144 145 /* expected-error {{missing argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop vectorize() 146 /* expected-error {{missing argument; expected an integer value}} */ #pragma clang loop interleave_count() 147 /* expected-error {{missing argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll() 148 /* expected-error {{missing argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute() 149 150 /* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, or distribute}} */ #pragma clang loop 151 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword 152 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword(enable) 153 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop vectorize(enable) badkeyword(4) 154 /* expected-warning {{extra tokens at end of '#pragma clang loop'}} */ #pragma clang loop vectorize(enable) , 155 while (i-4 < Length) { 156 List[i] = i; 157 } 158 159 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop vectorize_width(0) 160 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop interleave_count(0) 161 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop unroll_count(0) 162 163 /* expected-error {{expression is not an integral constant expression}} expected-note {{division by zero}} */ #pragma clang loop vectorize_width(10 / 0) 164 /* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop interleave_count(10 / 5 - 2) 165 while (i-5 < Length) { 166 List[i] = i; 167 } 168 169 test_nontype_template_vectorize<4>(List, Length); 170 /* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_vectorize<-1>(List, Length); 171 test_nontype_template_interleave<8>(List, Length); 172 /* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_interleave<-1>(List, Length); 173 174 /* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_char<'A'>(List, Length); // Loop hint arg cannot be a char. 175 /* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_bool<true>(List, Length); // Or a bool. 176 /* expected-note {{in instantiation of function template specialization}} */ test_type_template_vectorize<int>(List, Length); // Or a template type. 177 178 /* expected-error {{value '3000000000' is too large}} */ #pragma clang loop vectorize_width(3000000000) 179 /* expected-error {{value '3000000000' is too large}} */ #pragma clang loop interleave_count(3000000000) 180 /* expected-error {{value '3000000000' is too large}} */ #pragma clang loop unroll_count(3000000000) 181 while (i-6 < Length) { 182 List[i] = i; 183 } 184 185 /* expected-warning {{extra tokens at end of '#pragma clang loop'}} */ #pragma clang loop vectorize_width(1 +) 1 186 /* expected-warning {{extra tokens at end of '#pragma clang loop'}} */ #pragma clang loop vectorize_width(1) +1 187 const int VV = 4; 188 /* expected-error {{expected expression}} */ #pragma clang loop vectorize_width(VV +/ 2) 189 /* expected-error {{use of undeclared identifier 'undefined'}} */ #pragma clang loop vectorize_width(VV+undefined) 190 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize_width(1+(^*/2 * () 191 /* expected-warning {{extra tokens at end of '#pragma clang loop' - ignored}} */ #pragma clang loop vectorize_width(1+(-0[0])))))) 192 193 /* expected-error {{use of undeclared identifier 'badvalue'}} */ #pragma clang loop vectorize_width(badvalue) 194 /* expected-error {{use of undeclared identifier 'badvalue'}} */ #pragma clang loop interleave_count(badvalue) 195 /* expected-error {{use of undeclared identifier 'badvalue'}} */ #pragma clang loop unroll_count(badvalue) 196 while (i-6 < Length) { 197 List[i] = i; 198 } 199 200 /* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop vectorize(badidentifier) 201 /* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop interleave(badidentifier) 202 /* expected-error {{invalid argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll(badidentifier) 203 /* expected-error {{invalid argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute(badidentifier) 204 while (i-7 < Length) { 205 List[i] = i; 206 } 207 208 // PR20069 - Loop pragma arguments that are not identifiers or numeric 209 // constants crash FE. 210 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize(() 211 /* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop interleave(*) 212 /* expected-error {{invalid argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll(=) 213 /* expected-error {{invalid argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute(+) 214 /* expected-error {{type name requires a specifier or qualifier}} expected-error {{expected expression}} */ #pragma clang loop vectorize_width(^) 215 /* expected-error {{expected expression}} expected-error {{expected expression}} */ #pragma clang loop interleave_count(/) 216 /* expected-error {{expected expression}} expected-error {{expected expression}} */ #pragma clang loop unroll_count(==) 217 while (i-8 < Length) { 218 List[i] = i; 219 } 220 221 #pragma clang loop vectorize(enable) 222 /* expected-error {{expected a for, while, or do-while loop to follow '#pragma clang loop'}} */ int j = Length; 223 List[0] = List[1]; 224 225 while (j-1 < Length) { 226 List[j] = j; 227 } 228 229 // FIXME: A bug in ParsedAttributes causes the order of the attributes to be 230 // processed in reverse. Consequently, the errors occur on the first of pragma 231 // of the next three tests rather than the last, and the order of the kinds 232 // is also reversed. 233 234 /* expected-error {{incompatible directives 'vectorize(disable)' and 'vectorize_width(4)'}} */ #pragma clang loop vectorize_width(4) 235 #pragma clang loop vectorize(disable) 236 /* expected-error {{incompatible directives 'interleave(disable)' and 'interleave_count(4)'}} */ #pragma clang loop interleave_count(4) 237 #pragma clang loop interleave(disable) 238 /* expected-error {{incompatible directives 'unroll(disable)' and 'unroll_count(4)'}} */ #pragma clang loop unroll_count(4) 239 #pragma clang loop unroll(disable) 240 while (i-8 < Length) { 241 List[i] = i; 242 } 243 244 /* expected-error {{duplicate directives 'vectorize(disable)' and 'vectorize(enable)'}} */ #pragma clang loop vectorize(enable) 245 #pragma clang loop vectorize(disable) 246 /* expected-error {{duplicate directives 'interleave(disable)' and 'interleave(enable)'}} */ #pragma clang loop interleave(enable) 247 #pragma clang loop interleave(disable) 248 /* expected-error {{duplicate directives 'unroll(disable)' and 'unroll(full)'}} */ #pragma clang loop unroll(full) 249 #pragma clang loop unroll(disable) 250 /* expected-error {{duplicate directives 'distribute(disable)' and 'distribute(enable)'}} */ #pragma clang loop distribute(enable) 251 #pragma clang loop distribute(disable) 252 while (i-9 < Length) { 253 List[i] = i; 254 } 255 256 /* expected-error {{incompatible directives 'vectorize(disable)' and 'vectorize_width(4)'}} */ #pragma clang loop vectorize(disable) 257 #pragma clang loop vectorize_width(4) 258 /* expected-error {{incompatible directives 'interleave(disable)' and 'interleave_count(4)'}} */ #pragma clang loop interleave(disable) 259 #pragma clang loop interleave_count(4) 260 /* expected-error {{incompatible directives 'unroll(disable)' and 'unroll_count(4)'}} */ #pragma clang loop unroll(disable) 261 #pragma clang loop unroll_count(4) 262 while (i-10 < Length) { 263 List[i] = i; 264 } 265 266 /* expected-error {{duplicate directives 'vectorize_width(4)' and 'vectorize_width(8)'}} */ #pragma clang loop vectorize_width(8) 267 #pragma clang loop vectorize_width(4) 268 /* expected-error {{duplicate directives 'interleave_count(4)' and 'interleave_count(8)'}} */ #pragma clang loop interleave_count(8) 269 #pragma clang loop interleave_count(4) 270 /* expected-error {{duplicate directives 'unroll_count(4)' and 'unroll_count(8)'}} */ #pragma clang loop unroll_count(8) 271 #pragma clang loop unroll_count(4) 272 while (i-11 < Length) { 273 List[i] = i; 274 } 275 276 277 /* expected-error {{incompatible directives 'unroll(full)' and 'unroll_count(4)'}} */ #pragma clang loop unroll(full) 278 #pragma clang loop unroll_count(4) 279 while (i-11 < Length) { 280 List[i] = i; 281 } 282 283 #pragma clang loop interleave(enable) 284 /* expected-error {{expected statement}} */ } 285