1 // RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify %s 2 // RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++98 %s 3 // RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++11 %s 4 // RUN: %clang_cc1 -flax-vector-conversions=integer -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -DNO_LAX_FLOAT 5 // RUN: %clang_cc1 -flax-vector-conversions=none -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -DNO_LAX_FLOAT -DNO_LAX_INT 6 7 typedef char char16 __attribute__ ((__vector_size__ (16))); 8 typedef long long longlong16 __attribute__ ((__vector_size__ (16))); 9 typedef char char16_e __attribute__ ((__ext_vector_type__ (16))); 10 typedef long long longlong16_e __attribute__ ((__ext_vector_type__ (2))); 11 12 // Test overloading and function calls with vector types. 13 void f0(char16); // expected-note 0+{{candidate}} 14 15 void f0_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) { 16 f0(c16); 17 f0(ll16); 18 #ifdef NO_LAX_INT 19 // expected-error@-2 {{no matching function}} 20 #endif 21 f0(c16e); 22 f0(ll16e); 23 #ifdef NO_LAX_INT 24 // expected-error@-2 {{no matching function}} 25 #endif 26 } 27 28 int &f1(char16); 29 float &f1(longlong16); 30 31 void f1_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) { 32 int &ir1 = f1(c16); 33 float &fr1 = f1(ll16); 34 int &ir2 = f1(c16e); 35 float &fr2 = f1(ll16e); 36 } 37 38 void f2(char16_e); // expected-note 0+{{candidate}} 39 40 void f2_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) { 41 f2(c16); 42 f2(ll16); 43 #ifdef NO_LAX_INT 44 // expected-error@-2 {{no matching function}} 45 #endif 46 f2(c16e); 47 f2(ll16e); // expected-error{{no matching function}} 48 f2('a'); 49 f2(17); 50 } 51 52 // Test the conditional operator with vector types. 53 void conditional(bool Cond, char16 c16, longlong16 ll16, char16_e c16e, 54 longlong16_e ll16e) { 55 // Conditional operators with the same type. 56 __typeof__(Cond? c16 : c16) *c16p1 = &c16; 57 __typeof__(Cond? ll16 : ll16) *ll16p1 = &ll16; 58 __typeof__(Cond? c16e : c16e) *c16ep1 = &c16e; 59 __typeof__(Cond? ll16e : ll16e) *ll16ep1 = &ll16e; 60 61 // Conditional operators with similar types. 62 __typeof__(Cond? c16 : c16e) *c16ep2 = &c16e; 63 __typeof__(Cond? c16e : c16) *c16ep3 = &c16e; 64 __typeof__(Cond? ll16 : ll16e) *ll16ep2 = &ll16e; 65 __typeof__(Cond? ll16e : ll16) *ll16ep3 = &ll16e; 66 67 // Conditional operators with compatible types under -flax-vector-conversions (default) 68 (void)(Cond? c16 : ll16); 69 (void)(Cond? ll16e : c16e); 70 (void)(Cond? ll16e : c16); 71 #ifdef NO_LAX_INT 72 // expected-error@-4 {{cannot convert}} 73 // expected-error@-4 {{cannot convert}} 74 // expected-error@-4 {{cannot convert}} 75 #endif 76 } 77 78 // Test C++ cast'ing of vector types. 79 void casts(longlong16 ll16, longlong16_e ll16e) { 80 // C-style casts. 81 (void)(char16)ll16; 82 (void)(char16_e)ll16; 83 (void)(longlong16)ll16; 84 (void)(longlong16_e)ll16; 85 (void)(char16)ll16e; 86 (void)(char16_e)ll16e; 87 (void)(longlong16)ll16e; 88 (void)(longlong16_e)ll16e; 89 90 // Function-style casts. 91 (void)char16(ll16); 92 (void)char16_e(ll16); 93 (void)longlong16(ll16); 94 (void)longlong16_e(ll16); 95 (void)char16(ll16e); 96 (void)char16_e(ll16e); 97 (void)longlong16(ll16e); 98 (void)longlong16_e(ll16e); 99 100 // static_cast 101 (void)static_cast<char16>(ll16); 102 (void)static_cast<char16_e>(ll16); 103 #ifdef NO_LAX_INT 104 // expected-error@-3 {{not allowed}} 105 // expected-error@-3 {{not allowed}} 106 #endif 107 (void)static_cast<longlong16>(ll16); 108 (void)static_cast<longlong16_e>(ll16); 109 (void)static_cast<char16>(ll16e); 110 #ifdef NO_LAX_INT 111 // expected-error@-2 {{not allowed}} 112 #endif 113 (void)static_cast<char16_e>(ll16e); // expected-error{{static_cast from 'longlong16_e' (vector of 2 'long long' values) to 'char16_e' (vector of 16 'char' values) is not allowed}} 114 (void)static_cast<longlong16>(ll16e); 115 (void)static_cast<longlong16_e>(ll16e); 116 117 // reinterpret_cast 118 (void)reinterpret_cast<char16>(ll16); 119 (void)reinterpret_cast<char16_e>(ll16); 120 (void)reinterpret_cast<longlong16>(ll16); 121 (void)reinterpret_cast<longlong16_e>(ll16); 122 (void)reinterpret_cast<char16>(ll16e); 123 (void)reinterpret_cast<char16_e>(ll16e); 124 (void)reinterpret_cast<longlong16>(ll16e); 125 (void)reinterpret_cast<longlong16_e>(ll16e); 126 } 127 128 template<typename T> 129 struct convertible_to { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable}} 130 #if __cplusplus >= 201103L // C++11 or later 131 // expected-note@-2 3 {{candidate function (the implicit move assignment operator) not viable}} 132 #endif 133 operator T() const; 134 }; 135 136 void test_implicit_conversions(bool Cond, char16 c16, longlong16 ll16, 137 char16_e c16e, longlong16_e ll16e, 138 convertible_to<char16> to_c16, 139 convertible_to<longlong16> to_ll16, 140 convertible_to<char16_e> to_c16e, 141 convertible_to<longlong16_e> to_ll16e, 142 convertible_to<char16&> rto_c16, 143 convertible_to<char16_e&> rto_c16e) { 144 f0(to_c16); 145 f0(to_ll16); 146 #ifdef NO_LAX_INT 147 // expected-error@-2 {{no matching function}} 148 #endif 149 f0(to_c16e); 150 f0(to_ll16e); 151 #ifdef NO_LAX_INT 152 // expected-error@-2 {{no matching function}} 153 #endif 154 f2(to_c16); 155 f2(to_ll16); 156 #ifdef NO_LAX_INT 157 // expected-error@-2 {{no matching function}} 158 #endif 159 f2(to_c16e); 160 f2(to_ll16e); // expected-error{{no matching function}} 161 162 (void)(c16 == c16e); 163 (void)(c16 == to_c16); 164 (void)+to_c16; 165 (void)-to_c16; 166 (void)~to_c16; 167 (void)(to_c16 == to_c16e); 168 (void)(to_c16 != to_c16e); 169 (void)(to_c16 < to_c16e); 170 (void)(to_c16 <= to_c16e); 171 (void)(to_c16 > to_c16e); 172 (void)(to_c16 >= to_c16e); 173 (void)(to_c16 + to_c16); 174 (void)(to_c16 - to_c16); 175 (void)(to_c16 * to_c16); 176 (void)(to_c16 / to_c16); 177 (void)(rto_c16 = to_c16); // expected-error{{no viable overloaded '='}} 178 (void)(rto_c16 += to_c16); 179 (void)(rto_c16 -= to_c16); 180 (void)(rto_c16 *= to_c16); 181 (void)(rto_c16 /= to_c16); 182 183 (void)+to_c16e; 184 (void)-to_c16e; 185 (void)~to_c16e; 186 (void)(to_c16e == to_c16e); 187 (void)(to_c16e != to_c16e); 188 (void)(to_c16e < to_c16e); 189 (void)(to_c16e <= to_c16e); 190 (void)(to_c16e > to_c16e); 191 (void)(to_c16e >= to_c16e); 192 (void)(to_c16e + to_c16); 193 (void)(to_c16e - to_c16); 194 (void)(to_c16e * to_c16); 195 (void)(to_c16e / to_c16); 196 (void)(rto_c16e = to_c16); // expected-error{{no viable overloaded '='}} 197 (void)(rto_c16e += to_c16); 198 (void)(rto_c16e -= to_c16); 199 (void)(rto_c16e *= to_c16); 200 (void)(rto_c16e /= to_c16); 201 202 (void)+to_c16; 203 (void)-to_c16; 204 (void)~to_c16; 205 (void)(to_c16 == to_c16e); 206 (void)(to_c16 != to_c16e); 207 (void)(to_c16 < to_c16e); 208 (void)(to_c16 <= to_c16e); 209 (void)(to_c16 > to_c16e); 210 (void)(to_c16 >= to_c16e); 211 (void)(to_c16 + to_c16e); 212 (void)(to_c16 - to_c16e); 213 (void)(to_c16 * to_c16e); 214 (void)(to_c16 / to_c16e); 215 (void)(rto_c16 = c16e); // expected-error{{no viable overloaded '='}} 216 (void)(rto_c16 += to_c16e); 217 (void)(rto_c16 -= to_c16e); 218 (void)(rto_c16 *= to_c16e); 219 (void)(rto_c16 /= to_c16e); 220 221 (void)(Cond? to_c16 : to_c16e); 222 (void)(Cond? to_ll16e : to_ll16); 223 224 // These 2 are convertible with -flax-vector-conversions (default) 225 (void)(Cond? to_c16 : to_ll16); 226 (void)(Cond? to_c16e : to_ll16e); 227 #ifdef NO_LAX_INT 228 // expected-error@-3 {{cannot convert}} 229 // expected-error@-3 {{cannot convert}} 230 #endif 231 } 232 233 typedef float fltx2 __attribute__((__vector_size__(8))); 234 typedef float fltx4 __attribute__((__vector_size__(16))); 235 typedef double dblx2 __attribute__((__vector_size__(16))); 236 typedef double dblx4 __attribute__((__vector_size__(32))); 237 238 void accept_fltx2(fltx2); // expected-note{{candidate function not viable: no known conversion from 'double' to 'fltx2' (vector of 2 'float' values) for 1st argument}} 239 void accept_fltx4(fltx4); 240 void accept_dblx2(dblx2); 241 #ifdef NO_LAX_FLOAT 242 // expected-note@-3 {{no known conversion}} 243 // expected-note@-3 {{no known conversion}} 244 #endif 245 void accept_dblx4(dblx4); 246 void accept_bool(bool); // expected-note{{candidate function not viable: no known conversion from 'fltx2' (vector of 2 'float' values) to 'bool' for 1st argument}} 247 248 void test(fltx2 fltx2_val, fltx4 fltx4_val, dblx2 dblx2_val, dblx4 dblx4_val) { 249 // Exact matches 250 accept_fltx2(fltx2_val); 251 accept_fltx4(fltx4_val); 252 accept_dblx2(dblx2_val); 253 accept_dblx4(dblx4_val); 254 255 // Same-size conversions 256 accept_fltx4(dblx2_val); 257 accept_dblx2(fltx4_val); 258 #ifdef NO_LAX_FLOAT 259 // expected-error@-3 {{no matching function}} 260 // expected-error@-3 {{no matching function}} 261 #endif 262 263 // Conversion to bool. 264 accept_bool(fltx2_val); // expected-error{{no matching function for call to 'accept_bool'}} 265 266 // Scalar-to-vector conversions. 267 accept_fltx2(1.0); // expected-error{{no matching function for call to 'accept_fltx2'}} 268 } 269 270 typedef int intx4 __attribute__((__vector_size__(16))); 271 typedef int inte4 __attribute__((__ext_vector_type__(4))); 272 typedef float flte4 __attribute__((__ext_vector_type__(4))); 273 274 void test_mixed_vector_types(fltx4 f, intx4 n, flte4 g, inte4 m) { 275 (void)(f == g); 276 (void)(g != f); 277 (void)(f <= g); 278 (void)(g >= f); 279 (void)(f < g); 280 (void)(g > f); 281 282 (void)(+g); 283 (void)(-g); 284 285 (void)(f + g); 286 (void)(f - g); 287 (void)(f * g); 288 (void)(f / g); 289 (void)(f = g); 290 (void)(f += g); 291 (void)(f -= g); 292 (void)(f *= g); 293 (void)(f /= g); 294 295 296 (void)(n == m); 297 (void)(m != n); 298 (void)(n <= m); 299 (void)(m >= n); 300 (void)(n < m); 301 (void)(m > n); 302 303 (void)(+m); 304 (void)(-m); 305 (void)(~m); 306 307 (void)(n + m); 308 (void)(n - m); 309 (void)(n * m); 310 (void)(n / m); 311 (void)(n % m); 312 (void)(n = m); 313 (void)(n += m); 314 (void)(n -= m); 315 (void)(n *= m); 316 (void)(n /= m); 317 } 318 319 template<typename T> void test_pseudo_dtor_tmpl(T *ptr) { 320 ptr->~T(); 321 (*ptr).~T(); 322 } 323 324 void test_pseudo_dtor(fltx4 *f) { 325 f->~fltx4(); 326 (*f).~fltx4(); 327 test_pseudo_dtor_tmpl(f); 328 } 329 330 // PR16204 331 typedef __attribute__((ext_vector_type(4))) int vi4; 332 const int &reference_to_vec_element = vi4(1).x; 333 334 // PR12649 335 typedef bool bad __attribute__((__vector_size__(16))); // expected-error {{invalid vector element type 'bool'}} 336 337 namespace Templates { 338 template <typename Elt, unsigned Size> 339 struct TemplateVectorType { 340 typedef Elt __attribute__((__vector_size__(Size))) type; // #1 341 }; 342 343 template <int N, typename T> 344 struct PR15730 { 345 typedef T __attribute__((vector_size(N * sizeof(T)))) type; 346 typedef T __attribute__((vector_size(8192))) type2; // #2 347 typedef T __attribute__((vector_size(3))) type3; // #3 348 }; 349 350 void Init() { 351 const TemplateVectorType<float, 32>::type Works = {}; 352 const TemplateVectorType<int, 32>::type Works2 = {}; 353 // expected-error@#1 {{invalid vector element type 'bool'}} 354 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<bool, 32>' requested here}} 355 const TemplateVectorType<bool, 32>::type NoBool; 356 // expected-error@#1 {{invalid vector element type 'int __attribute__((ext_vector_type(4)))' (vector of 4 'int' values)}} 357 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int __attribute__((ext_vector_type(4))), 32>' requested here}} 358 const TemplateVectorType<vi4, 32>::type NoComplex; 359 // expected-error@#1 {{vector size not an integral multiple of component size}} 360 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 33>' requested here}} 361 const TemplateVectorType<int, 33>::type BadSize; 362 // expected-error@#1 {{vector size too large}} 363 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 8192>' requested here}} 364 const TemplateVectorType<int, 8192>::type TooLarge; 365 // expected-error@#1 {{zero vector size}} 366 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 0>' requested here}} 367 const TemplateVectorType<int, 0>::type Zero; 368 369 // expected-error@#2 {{vector size too large}} 370 // expected-error@#3 {{vector size not an integral multiple of component size}} 371 // expected-note@+1 {{in instantiation of template class 'Templates::PR15730<8, int>' requested here}} 372 const PR15730<8, int>::type PR15730_1 = {}; 373 // expected-error@#2 {{vector size too large}} 374 // expected-note@+1 {{in instantiation of template class 'Templates::PR15730<8, char>' requested here}} 375 const PR15730<8, char>::type2 PR15730_2 = {}; 376 } 377 378 } // namespace Templates 379 380 typedef int inte2 __attribute__((__ext_vector_type__(2))); 381 382 void test_vector_literal(inte4 res) { 383 inte2 a = (inte2)(1, 2); //expected-warning{{expression result unused}} 384 inte4 b = (inte4)(a, a); //expected-error{{C-style cast from vector 'inte2' (vector of 2 'int' values) to vector 'inte4' (vector of 4 'int' values) of different size}} //expected-warning{{expression result unused}} 385 } 386 387 typedef __attribute__((__ext_vector_type__(4))) float vector_float4; 388 typedef __attribute__((__ext_vector_type__(4))) int vector_int4; 389 390 namespace swizzle_template_confusion { 391 template<typename T> struct xyzw {}; 392 vector_int4 foo123(vector_float4 &A, vector_float4 &B) { 393 return A.xyzw < B.x && B.y > A.y; // OK, not a template-id 394 } 395 } 396 397 namespace swizzle_typo_correction { 398 template<typename T> struct xyzv {}; 399 vector_int4 foo123(vector_float4 &A, vector_float4 &B) { 400 return A.xyzw < B.x && B.y > A.y; // OK, not a typo for 'xyzv' 401 } 402 } 403