802 lines · cpp
1// RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify %s2// RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++98 %s3// RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++11 %s4// RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++20 %s5// RUN: %clang_cc1 -flax-vector-conversions=integer -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -DNO_LAX_FLOAT6// RUN: %clang_cc1 -flax-vector-conversions=none -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -DNO_LAX_FLOAT -DNO_LAX_INT7 8typedef char char16 __attribute__ ((__vector_size__ (16)));9typedef long long longlong16 __attribute__ ((__vector_size__ (16)));10typedef char char16_e __attribute__ ((__ext_vector_type__ (16)));11typedef long long longlong16_e __attribute__ ((__ext_vector_type__ (2)));12 13// Test overloading and function calls with vector types.14void f0(char16); // expected-note 0+{{candidate}}15 16void f0_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) {17 f0(c16);18 f0(ll16);19#ifdef NO_LAX_INT20 // expected-error@-2 {{no matching function}}21#endif22 f0(c16e);23 f0(ll16e);24#ifdef NO_LAX_INT25 // expected-error@-2 {{no matching function}}26#endif27}28 29int &f1(char16);30float &f1(longlong16);31 32void f1_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) {33 int &ir1 = f1(c16);34 float &fr1 = f1(ll16);35 int &ir2 = f1(c16e);36 float &fr2 = f1(ll16e);37}38 39void f2(char16_e); // expected-note 0+{{candidate}}40 41void f2_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) {42 f2(c16);43 f2(ll16);44#ifdef NO_LAX_INT45 // expected-error@-2 {{no matching function}}46#endif47 f2(c16e);48 f2(ll16e); // expected-error{{no matching function}}49 f2('a');50 f2(17);51}52 53// Test the conditional operator with vector types.54void conditional(bool Cond, char16 c16, longlong16 ll16, char16_e c16e,55 longlong16_e ll16e) {56 // Conditional operators with the same type.57 __typeof__(Cond? c16 : c16) *c16p1 = &c16;58 __typeof__(Cond? ll16 : ll16) *ll16p1 = &ll16;59 __typeof__(Cond? c16e : c16e) *c16ep1 = &c16e;60 __typeof__(Cond? ll16e : ll16e) *ll16ep1 = &ll16e;61 62 // Conditional operators with similar types.63 __typeof__(Cond? c16 : c16e) *c16ep2 = &c16e;64 __typeof__(Cond? c16e : c16) *c16ep3 = &c16e;65 __typeof__(Cond? ll16 : ll16e) *ll16ep2 = &ll16e;66 __typeof__(Cond? ll16e : ll16) *ll16ep3 = &ll16e;67 68 // Conditional operators with compatible types under -flax-vector-conversions (default)69 (void)(Cond? c16 : ll16);70 (void)(Cond? ll16e : c16e);71 (void)(Cond? ll16e : c16);72#ifdef NO_LAX_INT73 // expected-error@-4 {{cannot convert}}74 // expected-error@-4 {{cannot convert}}75 // expected-error@-4 {{cannot convert}}76#endif77}78 79// Test C++ cast'ing of vector types.80void casts(longlong16 ll16, longlong16_e ll16e) {81 // C-style casts.82 (void)(char16)ll16;83 (void)(char16_e)ll16;84 (void)(longlong16)ll16;85 (void)(longlong16_e)ll16;86 (void)(char16)ll16e;87 (void)(char16_e)ll16e;88 (void)(longlong16)ll16e;89 (void)(longlong16_e)ll16e;90 91 // Function-style casts.92 (void)char16(ll16);93 (void)char16_e(ll16);94 (void)longlong16(ll16);95 (void)longlong16_e(ll16);96 (void)char16(ll16e);97 (void)char16_e(ll16e);98 (void)longlong16(ll16e);99 (void)longlong16_e(ll16e);100 101 // static_cast102 (void)static_cast<char16>(ll16);103 (void)static_cast<char16_e>(ll16);104#ifdef NO_LAX_INT105 // expected-error@-3 {{not allowed}}106 // expected-error@-3 {{not allowed}}107#endif108 (void)static_cast<longlong16>(ll16);109 (void)static_cast<longlong16_e>(ll16);110 (void)static_cast<char16>(ll16e);111#ifdef NO_LAX_INT112 // expected-error@-2 {{not allowed}}113#endif114 (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}}115 (void)static_cast<longlong16>(ll16e);116 (void)static_cast<longlong16_e>(ll16e);117 118 // reinterpret_cast119 (void)reinterpret_cast<char16>(ll16);120 (void)reinterpret_cast<char16_e>(ll16);121 (void)reinterpret_cast<longlong16>(ll16);122 (void)reinterpret_cast<longlong16_e>(ll16);123 (void)reinterpret_cast<char16>(ll16e);124 (void)reinterpret_cast<char16_e>(ll16e);125 (void)reinterpret_cast<longlong16>(ll16e);126 (void)reinterpret_cast<longlong16_e>(ll16e);127}128 129template<typename T>130struct convertible_to { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable}}131#if __cplusplus >= 201103L // C++11 or later132// expected-note@-2 3 {{candidate function (the implicit move assignment operator) not viable}}133#endif134 operator T() const;135};136 137void test_implicit_conversions(bool Cond, char16 c16, longlong16 ll16,138 char16_e c16e, longlong16_e ll16e,139 convertible_to<char16> to_c16,140 convertible_to<longlong16> to_ll16,141 convertible_to<char16_e> to_c16e,142 convertible_to<longlong16_e> to_ll16e,143 convertible_to<char16&> rto_c16,144 convertible_to<char16_e&> rto_c16e) {145 f0(to_c16);146 f0(to_ll16);147#ifdef NO_LAX_INT148 // expected-error@-2 {{no matching function}}149#endif150 f0(to_c16e);151 f0(to_ll16e);152#ifdef NO_LAX_INT153 // expected-error@-2 {{no matching function}}154#endif155 f2(to_c16);156 f2(to_ll16);157#ifdef NO_LAX_INT158 // expected-error@-2 {{no matching function}}159#endif160 f2(to_c16e);161 f2(to_ll16e); // expected-error{{no matching function}}162 163 (void)(c16 == c16e);164 (void)(c16 == to_c16);165 (void)+to_c16;166 (void)-to_c16;167 (void)~to_c16;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_c16e);174 (void)(to_c16 + to_c16);175 (void)(to_c16 - to_c16);176 (void)(to_c16 * to_c16);177 (void)(to_c16 / to_c16);178 (void)(rto_c16 = to_c16); // expected-error{{no viable overloaded '='}}179 (void)(rto_c16 += to_c16);180 (void)(rto_c16 -= to_c16);181 (void)(rto_c16 *= to_c16);182 (void)(rto_c16 /= to_c16);183 184 (void)+to_c16e;185 (void)-to_c16e;186 (void)~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_c16e);193 (void)(to_c16e + to_c16);194 (void)(to_c16e - to_c16);195 (void)(to_c16e * to_c16);196 (void)(to_c16e / to_c16);197 (void)(rto_c16e = to_c16); // expected-error{{no viable overloaded '='}}198 (void)(rto_c16e += to_c16);199 (void)(rto_c16e -= to_c16);200 (void)(rto_c16e *= to_c16);201 (void)(rto_c16e /= to_c16);202 203 (void)+to_c16;204 (void)-to_c16;205 (void)~to_c16;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)(to_c16 / to_c16e);216 (void)(rto_c16 = c16e); // expected-error{{no viable overloaded '='}}217 (void)(rto_c16 += to_c16e);218 (void)(rto_c16 -= to_c16e);219 (void)(rto_c16 *= to_c16e);220 (void)(rto_c16 /= to_c16e);221 222 (void)(Cond? to_c16 : to_c16e);223 (void)(Cond? to_ll16e : to_ll16);224 225 // These 2 are convertible with -flax-vector-conversions (default)226 (void)(Cond? to_c16 : to_ll16);227 (void)(Cond? to_c16e : to_ll16e);228#ifdef NO_LAX_INT229 // expected-error@-3 {{cannot convert}}230 // expected-error@-3 {{cannot convert}}231#endif232}233 234typedef float fltx2 __attribute__((__vector_size__(8)));235typedef float fltx4 __attribute__((__vector_size__(16)));236typedef double dblx2 __attribute__((__vector_size__(16)));237typedef double dblx4 __attribute__((__vector_size__(32)));238 239void accept_fltx2(fltx2); // expected-note{{candidate function not viable: no known conversion from 'double' to 'fltx2' (vector of 2 'float' values) for 1st argument}}240void accept_fltx4(fltx4);241void accept_dblx2(dblx2);242#ifdef NO_LAX_FLOAT243// expected-note@-3 {{no known conversion}}244// expected-note@-3 {{no known conversion}}245#endif246void accept_dblx4(dblx4);247void accept_bool(bool); // expected-note{{candidate function not viable: no known conversion from 'fltx2' (vector of 2 'float' values) to 'bool' for 1st argument}}248 249void test(fltx2 fltx2_val, fltx4 fltx4_val, dblx2 dblx2_val, dblx4 dblx4_val) {250 // Exact matches251 accept_fltx2(fltx2_val);252 accept_fltx4(fltx4_val);253 accept_dblx2(dblx2_val);254 accept_dblx4(dblx4_val);255 256 // Same-size conversions257 accept_fltx4(dblx2_val);258 accept_dblx2(fltx4_val);259#ifdef NO_LAX_FLOAT260 // expected-error@-3 {{no matching function}}261 // expected-error@-3 {{no matching function}}262#endif263 264 // Conversion to bool.265 accept_bool(fltx2_val); // expected-error{{no matching function for call to 'accept_bool'}}266 267 // Scalar-to-vector conversions.268 accept_fltx2(1.0); // expected-error{{no matching function for call to 'accept_fltx2'}}269}270 271typedef int intx4 __attribute__((__vector_size__(16)));272typedef int inte4 __attribute__((__ext_vector_type__(4)));273typedef float flte4 __attribute__((__ext_vector_type__(4)));274 275void test_mixed_vector_types(fltx4 f, intx4 n, flte4 g, inte4 m) {276 (void)(f == g);277 (void)(g != f);278 (void)(f <= g);279 (void)(g >= f);280 (void)(f < g);281 (void)(g > f);282 283 (void)(+g);284 (void)(-g);285 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 (void)(f /= g);295 296 297 (void)(n == m);298 (void)(m != n);299 (void)(n <= m);300 (void)(m >= n);301 (void)(n < m);302 (void)(m > n);303 304 (void)(+m);305 (void)(-m);306 (void)(~m);307 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 (void)(n /= m);318}319 320template<typename T> void test_pseudo_dtor_tmpl(T *ptr) {321 ptr->~T();322 (*ptr).~T();323}324 325void test_pseudo_dtor(fltx4 *f) {326 f->~fltx4();327 (*f).~fltx4();328 test_pseudo_dtor_tmpl(f);329}330 331// PR16204332typedef __attribute__((ext_vector_type(4))) int vi4;333const int &reference_to_vec_element = vi4(1).x;334 335// PR12649336typedef bool bad __attribute__((__vector_size__(16))); // expected-error {{invalid vector element type 'bool'}}337 338namespace Templates {339template <typename Elt, unsigned long long Size>340struct TemplateVectorType {341 typedef Elt __attribute__((__vector_size__(Size))) type; // #1342};343 344template <int N, typename T>345struct PR15730 {346 typedef T __attribute__((vector_size(N * sizeof(T)))) type;347 typedef T __attribute__((vector_size(0x1000000000))) type2; // #2348 typedef T __attribute__((vector_size(3))) type3; // #3349};350 351void Init() {352 const TemplateVectorType<float, 32>::type Works = {};353 const TemplateVectorType<int, 32>::type Works2 = {};354 // expected-error@#1 {{invalid vector element type 'bool'}}355 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<bool, 32>' requested here}}356 const TemplateVectorType<bool, 32>::type NoBool = {};357 // expected-error@#1 {{invalid vector element type 'int __attribute__((ext_vector_type(4)))' (vector of 4 'int' values)}}358 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int __attribute__((ext_vector_type(4))), 32>' requested here}}359 const TemplateVectorType<vi4, 32>::type NoComplex = {};360 // expected-error@#1 {{vector size not an integral multiple of component size}}361 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 33>' requested here}}362 const TemplateVectorType<int, 33>::type BadSize = {};363 const TemplateVectorType<int, 3200>::type Large = {};364 // expected-error@#1 {{vector size too large}}365 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 68719476736>' requested here}}366 const TemplateVectorType<int, 0x1000000000>::type TooLarge = {};367 // expected-error@#1 {{zero vector size}}368 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 0>' requested here}}369 const TemplateVectorType<int, 0>::type Zero = {};370 371 // expected-error@#2 {{vector size too large}}372 // expected-error@#3 {{vector size not an integral multiple of component size}}373 // expected-note@+1 {{in instantiation of template class 'Templates::PR15730<8, int>' requested here}}374 const PR15730<8, int>::type PR15730_1 = {};375 // expected-error@#2 {{vector size too large}}376 // expected-note@+1 {{in instantiation of template class 'Templates::PR15730<8, char>' requested here}}377 const PR15730<8, char>::type2 PR15730_2 = {};378}379 380} // namespace Templates381 382typedef int inte2 __attribute__((__ext_vector_type__(2)));383 384void test_vector_literal(inte4 res) {385 inte2 a = (inte2)(1, 2); //expected-warning{{left operand of comma operator has no effect}}386 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{{left operand of comma operator has no effect}}387}388 389typedef __attribute__((__ext_vector_type__(4))) float vector_float4;390typedef __attribute__((__ext_vector_type__(4))) int vector_int4;391 392namespace swizzle_template_confusion {393 template<typename T> struct xyzw {};394 vector_int4 foo123(vector_float4 &A, vector_float4 &B) {395 return A.xyzw < B.x && B.y > A.y; // OK, not a template-id396 }397}398 399namespace swizzle_typo_correction {400 template<typename T> struct xyzv {};401 vector_int4 foo123(vector_float4 &A, vector_float4 &B) {402 return A.xyzw < B.x && B.y > A.y; // OK, not a typo for 'xyzv'403 }404}405 406namespace PR45299 {407typedef float float4 __attribute__((vector_size(16)));408 409// In this example, 'k' is value dependent. PR45299 reported that this asserted410// because of that, since the truncation check attempted to constant evaluate k,411// which it could not do because it is dependent.412template <typename T>413struct NormalMember {414 float4 f(float4 x) {415 return k * x;416 }417 float k;418};419 420#if __cplusplus >= 201103L421// This should not diagnose, since the constant evaluator (during instantiation)422// can tell that this isn't a truncation.423template <typename T>424struct ConstantValueNoDiag {425 float4 f(float4 x) {426 return k * x;427 }428 static constexpr double k = 1;429};430template <typename T, int N>431struct ConstantValueNoDiagDependentValue {432 float4 f(float4 x) {433 return k * x;434 }435 static constexpr double k = N;436};437 438// The following two both diagnose because they cause a truncation. Test both439// the dependent type and non-dependent type versions.440template <typename T>441struct DiagTrunc {442 float4 f(float4 x) {443 // expected-error@+1{{as implicit conversion would cause truncation}}444 return k * x;445 }446 static constexpr double k = 1340282346638528859811704183484516925443.000000;447};448template <typename T, int N>449struct DiagTruncDependentValue {450 float4 f(float4 x) {451 // expected-error@+1{{as implicit conversion would cause truncation}}452 return k * x;453 }454 static constexpr double k = N + 1340282346638528859811704183484516925443.000000;455};456template <typename T>457struct DiagTruncDependentType {458 float4 f(float4 x) {459 // expected-error@+1{{as implicit conversion would cause truncation}}460 return k * x;461 }462 static constexpr T k = 1340282346638528859811704183484516925443.000000;463};464 465template <typename T>466struct PR45298 {467 T k1 = T(0);468};469 470// Ensure this no longer asserts.471template <typename T>472struct PR45298Consumer {473 float4 f(float4 x) {474 return (float)s.k1 * x;475 }476 477 PR45298<T> s;478};479#endif // __cplusplus >= 201103L480 481void use() {482 float4 theFloat4;483 NormalMember<double>().f(theFloat4);484#if __cplusplus >= 201103L485 ConstantValueNoDiag<double>().f(theFloat4);486 ConstantValueNoDiagDependentValue<double, 1>().f(theFloat4);487 DiagTrunc<double>().f(theFloat4);488 // expected-note@+1{{in instantiation of member function}}489 DiagTruncDependentValue<double, 0>().f(theFloat4);490 // expected-note@+1{{in instantiation of member function}}491 DiagTruncDependentType<double>().f(theFloat4);492 PR45298Consumer<double>().f(theFloat4);493#endif // __cplusplus >= 201103L494}495}496 497namespace rdar60092165 {498template <class T> void f() {499 typedef T first_type __attribute__((vector_size(sizeof(T) * 4)));500 typedef T second_type __attribute__((vector_size(sizeof(T) * 4)));501 502 second_type st;503}504}505 506namespace PR45780 {507enum E { Value = 15 };508void use(char16 c) {509 E e;510 c &Value; // expected-error{{cannot convert between scalar type 'PR45780::E' and vector type 'char16'}}511 c == Value; // expected-error{{cannot convert between scalar type 'PR45780::E' and vector type 'char16'}}512 e | c; // expected-error{{cannot convert between scalar type 'E' and vector type 'char16'}}513 e != c; // expected-error{{cannot convert between scalar type 'E' and vector type 'char16'}}514}515 516} // namespace PR45780517 518namespace PR48540 {519// The below used to cause an OOM error, or an assert, make sure it is still520// valid.521int (__attribute__((vector_size(16))) a);522 523template <typename T, int I>524struct S {525 T (__attribute__((vector_size(16))) a);526 int (__attribute__((vector_size(I))) b);527 T (__attribute__((vector_size(I))) c);528};529 530void use() {531 S<int, 16> s;532}533} // namespace PR48540534 535#if __cplusplus >= 202002L // C++20 or later536// Don't crash due to missing integer ranks.537char8_t v1 __attribute__((vector_size(16)));538char16_t v2 __attribute__((vector_size(16)));539char32_t v3 __attribute__((vector_size(16)));540wchar_t v4 __attribute__((vector_size(16)));541void triggerIntegerRankCheck() {542 auto b1 = (v1 >= 0x12);543 auto b2 = (v2 >= 0x12);544 auto b3 = (v3 >= 0x12);545 auto b4 = (v4 >= 0x12);546}547#endif548 549namespace all_operators {550typedef unsigned int v2u __attribute__((ext_vector_type(2)));551typedef float v2f __attribute__((ext_vector_type(2)));552 553void test_int_vector_scalar(unsigned int ua, v2u v2ua) {554 // Operators with one integer vector and one integer scalar operand. The scalar will splat.555 (void)(v2ua + ua);556 (void)(ua + v2ua);557 (void)(v2ua - ua);558 (void)(ua - v2ua);559 (void)(v2ua * ua);560 (void)(ua * v2ua);561 (void)(v2ua / ua);562 (void)(ua / v2ua);563 (void)(v2ua % ua);564 (void)(ua % v2ua);565 566 (void)(v2ua == ua);567 (void)(ua == v2ua);568 (void)(v2ua != ua);569 (void)(ua != v2ua);570 (void)(v2ua <= ua);571 (void)(ua <= v2ua);572 (void)(v2ua >= ua);573 (void)(ua >= v2ua);574 (void)(v2ua < ua);575 (void)(ua < v2ua);576 (void)(v2ua > ua);577 (void)(ua > v2ua);578 (void)(v2ua && ua);579 (void)(ua && v2ua);580 (void)(v2ua || ua);581 (void)(ua || v2ua);582 583 (void)(v2ua & ua);584 (void)(ua & v2ua);585 (void)(v2ua | ua);586 (void)(ua | v2ua);587 (void)(v2ua ^ ua);588 (void)(ua ^ v2ua);589 (void)(v2ua << ua);590 (void)(ua << v2ua);591 (void)(v2ua >> ua);592 (void)(ua >> v2ua);593 594 v2ua += ua;595 v2ua -= ua;596 v2ua *= ua;597 v2ua /= ua;598 v2ua %= ua;599 v2ua &= ua;600 v2ua |= ua;601 v2ua ^= ua;602 v2ua >>= ua;603 v2ua <<= ua;604 605 ua += v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}606 ua -= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}607 ua *= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}608 ua /= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}609 ua %= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}610 ua &= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}611 ua |= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}612 ua ^= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}613 ua >>= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}614 ua <<= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}615}616 617void test_float_vector_scalar(float fa, unsigned int ua, v2f v2fa) {618 // Operators with one float vector and one float scalar operand. The scalar will splat.619 (void)(v2fa + fa);620 (void)(fa + v2fa);621 (void)(v2fa - fa);622 (void)(fa - v2fa);623 (void)(v2fa * fa);624 (void)(fa * v2fa);625 (void)(v2fa / fa);626 (void)(fa / v2fa);627 (void)(v2fa % fa); // expected-error{{invalid operands to binary expression}}628 (void)(fa % v2fa); // expected-error{{invalid operands to binary expression}}629 630 (void)(v2fa == fa);631 (void)(fa == v2fa);632 (void)(v2fa != fa);633 (void)(fa != v2fa);634 (void)(v2fa <= fa);635 (void)(fa <= v2fa);636 (void)(v2fa >= fa);637 (void)(fa >= v2fa);638 (void)(v2fa < fa);639 (void)(fa < v2fa);640 (void)(v2fa > fa);641 (void)(fa > v2fa);642 (void)(v2fa && fa);643 (void)(fa && v2fa);644 (void)(v2fa || fa);645 (void)(fa || v2fa);646 647 (void)(v2fa & fa); // expected-error{{invalid operands to binary expression}}648 (void)(fa & v2fa); // expected-error{{invalid operands to binary expression}}649 (void)(v2fa | fa); // expected-error{{invalid operands to binary expression}}650 (void)(fa | v2fa); // expected-error{{invalid operands to binary expression}}651 (void)(v2fa ^ fa); // expected-error{{invalid operands to binary expression}}652 (void)(fa ^ v2fa); // expected-error{{invalid operands to binary expression}}653 (void)(v2fa << fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}654 (void)(v2fa << ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}655 (void)(fa << v2fa); // expected-error{{used type 'float' where integer is required}}656 (void)(ua << v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}657 (void)(v2fa >> fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}658 (void)(v2fa >> ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}659 (void)(fa >> v2fa); // expected-error{{used type 'float' where integer is required}}660 (void)(ua >> v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}661 662 v2fa += fa;663 v2fa -= fa;664 v2fa *= fa;665 v2fa /= fa;666 v2fa %= fa; // expected-error{{invalid operands to binary expression}}667 v2fa &= fa; // expected-error{{invalid operands to binary expression}}668 v2fa |= fa; // expected-error{{invalid operands to binary expression}}669 v2fa ^= fa; // expected-error{{invalid operands to binary expression}}670 v2fa >>= fa; // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}671 v2fa <<= fa; // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}672 673 fa += v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}674 fa -= v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}675 fa *= v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}676 fa /= v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}677 fa %= v2fa; // expected-error{{invalid operands to binary expression}}678 fa &= v2fa; // expected-error{{invalid operands to binary expression}}679 fa |= v2fa; // expected-error{{invalid operands to binary expression}}680 fa ^= v2fa; // expected-error{{invalid operands to binary expression}}681 fa >>= v2fa; // expected-error{{used type 'float' where integer is required}}682 fa <<= v2fa; // expected-error{{used type 'float' where integer is required}}683}684 685enum Enum { ENUM };686 687void test_enum_vector_scalar(Enum ea, v2u v2ua) {688 // Operators with one integer vector and one enum scalar operand.689 // The scalar will have an implicit conversion to an integral type and then splat.690 // FIXME: These should behave the same as in C, they should be accepted via691 // the enum converting to an integer then splatting to the vector width.692 // https://github.com/llvm/llvm-project/issues/62869693 (void)(v2ua + ea); // expected-error{{cannot convert between vector values of different size}}694 (void)(ea + v2ua); // expected-error{{cannot convert between vector values of different size}}695 (void)(v2ua - ea); // expected-error{{cannot convert between vector values of different size}}696 (void)(ea - v2ua); // expected-error{{cannot convert between vector values of different size}}697 (void)(v2ua * ea); // expected-error{{cannot convert between vector values of different size}}698 (void)(ea * v2ua); // expected-error{{cannot convert between vector values of different size}}699 (void)(v2ua / ea); // expected-error{{cannot convert between vector values of different size}}700 (void)(ea / v2ua); // expected-error{{cannot convert between vector values of different size}}701 (void)(v2ua % ea); // expected-error{{cannot convert between vector values of different size}}702 (void)(ea % v2ua); // expected-error{{cannot convert between vector values of different size}}703 704 (void)(v2ua == ea); // expected-error{{cannot convert between vector values of different size}}705 (void)(ea == v2ua); // expected-error{{cannot convert between vector values of different size}}706 (void)(v2ua != ea); // expected-error{{cannot convert between vector values of different size}}707 (void)(ea != v2ua); // expected-error{{cannot convert between vector values of different size}}708 (void)(v2ua <= ea); // expected-error{{cannot convert between vector values of different size}}709 (void)(ea <= v2ua); // expected-error{{cannot convert between vector values of different size}}710 (void)(v2ua >= ea); // expected-error{{cannot convert between vector values of different size}}711 (void)(ea >= v2ua); // expected-error{{cannot convert between vector values of different size}}712 (void)(v2ua < ea); // expected-error{{cannot convert between vector values of different size}}713 (void)(ea < v2ua); // expected-error{{cannot convert between vector values of different size}}714 (void)(v2ua > ea); // expected-error{{cannot convert between vector values of different size}}715 (void)(ea > v2ua); // expected-error{{cannot convert between vector values of different size}}716 (void)(v2ua && ea); // expected-error{{cannot convert between vector values of different size}}717 // expected-error@-1{{invalid operands to binary expression}}718 (void)(ea && v2ua); // expected-error{{cannot convert between vector values of different size}}719 // expected-error@-1{{invalid operands to binary expression}}720 (void)(v2ua || ea); // expected-error{{cannot convert between vector values of different size}}721 // expected-error@-1{{invalid operands to binary expression}}722 (void)(ea || v2ua); // expected-error{{cannot convert between vector values of different size}}723 // expected-error@-1{{invalid operands to binary expression}}724 725 (void)(v2ua & ea); // expected-error{{cannot convert between vector values of different size}}726 (void)(ea & v2ua); // expected-error{{cannot convert between vector values of different size}}727 (void)(v2ua | ea); // expected-error{{cannot convert between vector values of different size}}728 (void)(ea | v2ua); // expected-error{{cannot convert between vector values of different size}}729 (void)(v2ua ^ ea); // expected-error{{cannot convert between vector values of different size}}730 (void)(ea ^ v2ua); // expected-error{{cannot convert between vector values of different size}}731 // FIXME: Vector/scalar shifts cause an assertion failure732 // https://github.com/llvm/llvm-project/issues/62870733 // (void)(v2ua << ea);734 // (void)(ea << v2ua);735 // (void)(v2ua >> ea);736 // (void)(ea >> v2ua);737 738 v2ua += ea; // expected-error{{cannot convert between vector values of different size}}739 v2ua -= ea; // expected-error{{cannot convert between vector values of different size}}740 v2ua *= ea; // expected-error{{cannot convert between vector values of different size}}741 v2ua /= ea; // expected-error{{cannot convert between vector values of different size}}742 v2ua %= ea; // expected-error{{cannot convert between vector values of different size}}743 v2ua &= ea; // expected-error{{cannot convert between vector values of different size}}744 v2ua |= ea; // expected-error{{cannot convert between vector values of different size}}745 v2ua ^= ea; // expected-error{{cannot convert between vector values of different size}}746 // FIXME: Vector/scalar shifts cause an assertion failure747 // https://github.com/llvm/llvm-project/issues/62870748 // v2ua >>= ea;749 // v2ua <<= ea;750 751 ea += v2ua; // expected-error{{cannot convert between vector values of different size}}752 ea -= v2ua; // expected-error{{cannot convert between vector values of different size}}753 ea *= v2ua; // expected-error{{cannot convert between vector values of different size}}754 ea /= v2ua; // expected-error{{cannot convert between vector values of different size}}755 ea %= v2ua; // expected-error{{cannot convert between vector values of different size}}756 ea &= v2ua; // expected-error{{cannot convert between vector values of different size}}757 ea |= v2ua; // expected-error{{cannot convert between vector values of different size}}758 ea ^= v2ua; // expected-error{{cannot convert between vector values of different size}}759 // FIXME: Vector/scalar shifts cause an assertion failure760 // https://github.com/llvm/llvm-project/issues/62870761 // ea >>= v2ua; // not-expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}762 // ea <<= v2ua; // not-expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}763}764 765#if __cplusplus >= 201103L // C++11 or later766enum class EnumClass { ENUM };767 768void test_scoped_enum_vector(EnumClass ea, v2u v2ua) {769 // Scoped enumerations are only compatible with exactly matching types. They shouldn't integral promote.770 (void)(v2ua + ea); // expected-error{{cannot convert between vector and non-scalar values}}771 (void)(ea + v2ua); // expected-error{{cannot convert between vector and non-scalar values}}772}773#endif774}775 776namespace GH105486 {777__attribute__((__vector_size__(sizeof(double)))) double a;778double b = a - (long)(*0); // expected-error {{indirection requires pointer operand ('int' invalid)}} \779 // expected-error {{cannot initialize a variable of type 'double' with an rvalue of type '__attribute__((__vector_size__(1 * sizeof(double)))) double' (vector of 1 'double' value)}}780 781__attribute__((__vector_size__(sizeof(long)))) long c;782long d = c - (long)(*0); // expected-error {{indirection requires pointer operand ('int' invalid)}} \783 // expected-error {{cannot initialize a variable of type 'long' with an rvalue of type '__attribute__((__vector_size__(1 * sizeof(long)))) long' (vector of 1 'long' value)}}784 785const long long e = *0; // expected-error {{indirection requires pointer operand ('int' invalid)}}786double f = a - e; // expected-error {{cannot initialize a variable of type 'double' with an rvalue of type '__attribute__((__vector_size__(1 * sizeof(double)))) double' (vector of 1 'double' value)}}787int h = c - e; // expected-error {{cannot initialize a variable of type 'int' with an rvalue of type '__attribute__((__vector_size__(1 * sizeof(long)))) long' (vector of 1 'long' value)}}788}789 790typedef int v_neg_size __attribute__((vector_size(-8))); // expected-error{{vector must have non-negative size}}791typedef int v_neg_size_2 __attribute__((vector_size(-1 * 8))); // expected-error{{vector must have non-negative size}}792typedef int v_ext_neg_size __attribute__((ext_vector_type(-8))); // expected-error{{vector must have non-negative size}}793typedef int v_ext_neg_size2 __attribute__((ext_vector_type(-1 * 8))); // expected-error{{vector must have non-negative size}}794 795 796#if __cplusplus >= 201103L797 798template <int N> using templated_v_size = int __attribute__((vector_size(N))); // expected-error{{vector must have non-negative size}}799templated_v_size<-8> templated_v_neg_size; //expected-note{{in instantiation of template type alias 'templated_v_size' requested here}}800 801#endif802