| 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=all -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++20 %s |
| 5 |
// RUN: %clang_cc1 -flax-vector-conversions=integer -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -DNO_LAX_FLOAT |
| 6 |
// RUN: %clang_cc1 -flax-vector-conversions=none -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -DNO_LAX_FLOAT -DNO_LAX_INT |
| 7 |
|
| 8 |
typedef char char16 __attribute__ ((__vector_size__ (16))); |
| 9 |
typedef long long longlong16 __attribute__ ((__vector_size__ (16))); |
| 10 |
typedef char char16_e __attribute__ ((__ext_vector_type__ (16))); |
| 11 |
typedef long long longlong16_e __attribute__ ((__ext_vector_type__ (2))); |
| 12 |
|
| 13 |
// Test overloading and function calls with vector types. |
| 14 |
void f0(char16); // expected-note 0+{{candidate}} |
| 15 |
|
| 16 |
void f0_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) { |
| 17 |
f0(c16); |
| 18 |
f0(ll16); |
| 19 |
#ifdef NO_LAX_INT |
| 20 |
// expected-error@-2 {{no matching function}} |
| 21 |
#endif |
| 22 |
f0(c16e); |
| 23 |
f0(ll16e); |
| 24 |
#ifdef NO_LAX_INT |
| 25 |
// expected-error@-2 {{no matching function}} |
| 26 |
#endif |
| 27 |
} |
| 28 |
|
| 29 |
int &f1(char16); |
| 30 |
float &f1(longlong16); |
| 31 |
|
| 32 |
void 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 |
|
| 39 |
void f2(char16_e); // expected-note 0+{{candidate}} |
| 40 |
|
| 41 |
void f2_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) { |
| 42 |
f2(c16); |
| 43 |
f2(ll16); |
| 44 |
#ifdef NO_LAX_INT |
| 45 |
// expected-error@-2 {{no matching function}} |
| 46 |
#endif |
| 47 |
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. |
| 54 |
void 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_INT |
| 73 |
// expected-error@-4 {{cannot convert}} |
| 74 |
// expected-error@-4 {{cannot convert}} |
| 75 |
// expected-error@-4 {{cannot convert}} |
| 76 |
#endif |
| 77 |
} |
| 78 |
|
| 79 |
// Test C++ cast'ing of vector types. |
| 80 |
void 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_cast |
| 102 |
(void)static_cast<char16>(ll16); |
| 103 |
(void)static_cast<char16_e>(ll16); |
| 104 |
#ifdef NO_LAX_INT |
| 105 |
// expected-error@-3 {{not allowed}} |
| 106 |
// expected-error@-3 {{not allowed}} |
| 107 |
#endif |
| 108 |
(void)static_cast<longlong16>(ll16); |
| 109 |
(void)static_cast<longlong16_e>(ll16); |
| 110 |
(void)static_cast<char16>(ll16e); |
| 111 |
#ifdef NO_LAX_INT |
| 112 |
// expected-error@-2 {{not allowed}} |
| 113 |
#endif |
| 114 |
(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_cast |
| 119 |
(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 |
|
| 129 |
template<typename T> |
| 130 |
struct convertible_to { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable}} |
| 131 |
#if __cplusplus >= 201103L // C++11 or later |
| 132 |
// expected-note@-2 3 {{candidate function (the implicit move assignment operator) not viable}} |
| 133 |
#endif |
| 134 |
operator T() const; |
| 135 |
}; |
| 136 |
|
| 137 |
void 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_INT |
| 148 |
// expected-error@-2 {{no matching function}} |
| 149 |
#endif |
| 150 |
f0(to_c16e); |
| 151 |
f0(to_ll16e); |
| 152 |
#ifdef NO_LAX_INT |
| 153 |
// expected-error@-2 {{no matching function}} |
| 154 |
#endif |
| 155 |
f2(to_c16); |
| 156 |
f2(to_ll16); |
| 157 |
#ifdef NO_LAX_INT |
| 158 |
// expected-error@-2 {{no matching function}} |
| 159 |
#endif |
| 160 |
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_INT |
| 229 |
// expected-error@-3 {{cannot convert}} |
| 230 |
// expected-error@-3 {{cannot convert}} |
| 231 |
#endif |
| 232 |
} |
| 233 |
|
| 234 |
typedef float fltx2 __attribute__((__vector_size__(8))); |
| 235 |
typedef float fltx4 __attribute__((__vector_size__(16))); |
| 236 |
typedef double dblx2 __attribute__((__vector_size__(16))); |
| 237 |
typedef double dblx4 __attribute__((__vector_size__(32))); |
| 238 |
|
| 239 |
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}} |
| 240 |
void accept_fltx4(fltx4); |
| 241 |
void accept_dblx2(dblx2); |
| 242 |
#ifdef NO_LAX_FLOAT |
| 243 |
// expected-note@-3 {{no known conversion}} |
| 244 |
// expected-note@-3 {{no known conversion}} |
| 245 |
#endif |
| 246 |
void accept_dblx4(dblx4); |
| 247 |
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}} |
| 248 |
|
| 249 |
void test(fltx2 fltx2_val, fltx4 fltx4_val, dblx2 dblx2_val, dblx4 dblx4_val) { |
| 250 |
// Exact matches |
| 251 |
accept_fltx2(fltx2_val); |
| 252 |
accept_fltx4(fltx4_val); |
| 253 |
accept_dblx2(dblx2_val); |
| 254 |
accept_dblx4(dblx4_val); |
| 255 |
|
| 256 |
// Same-size conversions |
| 257 |
accept_fltx4(dblx2_val); |
| 258 |
accept_dblx2(fltx4_val); |
| 259 |
#ifdef NO_LAX_FLOAT |
| 260 |
// expected-error@-3 {{no matching function}} |
| 261 |
// expected-error@-3 {{no matching function}} |
| 262 |
#endif |
| 263 |
|
| 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 |
|
| 271 |
typedef int intx4 __attribute__((__vector_size__(16))); |
| 272 |
typedef int inte4 __attribute__((__ext_vector_type__(4))); |
| 273 |
typedef float flte4 __attribute__((__ext_vector_type__(4))); |
| 274 |
|
| 275 |
void 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 |
|
| 320 |
template<typename T> void test_pseudo_dtor_tmpl(T *ptr) { |
| 321 |
ptr->~T(); |
| 322 |
(*ptr).~T(); |
| 323 |
} |
| 324 |
|
| 325 |
void test_pseudo_dtor(fltx4 *f) { |
| 326 |
f->~fltx4(); |
| 327 |
(*f).~fltx4(); |
| 328 |
test_pseudo_dtor_tmpl(f); |
| 329 |
} |
| 330 |
|
| 331 |
// PR16204 |
| 332 |
typedef __attribute__((ext_vector_type(4))) int vi4; |
| 333 |
const int &reference_to_vec_element = vi4(1).x; |
| 334 |
|
| 335 |
// PR12649 |
| 336 |
typedef bool bad __attribute__((__vector_size__(16))); // expected-error {{invalid vector element type 'bool'}} |
| 337 |
|
| 338 |
namespace Templates { |
| 339 |
template <typename Elt, unsigned long long Size> |
| 340 |
struct TemplateVectorType { |
| 341 |
typedef Elt __attribute__((__vector_size__(Size))) type; // #1 |
| 342 |
}; |
| 343 |
|
| 344 |
template <int N, typename T> |
| 345 |
struct PR15730 { |
| 346 |
typedef T __attribute__((vector_size(N * sizeof(T)))) type; |
| 347 |
typedef T __attribute__((vector_size(0x1000000000))) type2; // #2 |
| 348 |
typedef T __attribute__((vector_size(3))) type3; // #3 |
| 349 |
}; |
| 350 |
|
| 351 |
void 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 Templates |
| 381 |
|
| 382 |
typedef int inte2 __attribute__((__ext_vector_type__(2))); |
| 383 |
|
| 384 |
void 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 |
|
| 389 |
typedef __attribute__((__ext_vector_type__(4))) float vector_float4; |
| 390 |
typedef __attribute__((__ext_vector_type__(4))) int vector_int4; |
| 391 |
|
| 392 |
namespace 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-id |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
namespace 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 |
|
| 406 |
namespace PR45299 { |
| 407 |
typedef float float4 __attribute__((vector_size(16))); |
| 408 |
|
| 409 |
// In this example, 'k' is value dependent. PR45299 reported that this asserted |
| 410 |
// because of that, since the truncation check attempted to constant evaluate k, |
| 411 |
// which it could not do because it is dependent. |
| 412 |
template <typename T> |
| 413 |
struct NormalMember { |
| 414 |
float4 f(float4 x) { |
| 415 |
return k * x; |
| 416 |
} |
| 417 |
float k; |
| 418 |
}; |
| 419 |
|
| 420 |
#if __cplusplus >= 201103L |
| 421 |
// This should not diagnose, since the constant evaluator (during instantiation) |
| 422 |
// can tell that this isn't a truncation. |
| 423 |
template <typename T> |
| 424 |
struct ConstantValueNoDiag { |
| 425 |
float4 f(float4 x) { |
| 426 |
return k * x; |
| 427 |
} |
| 428 |
static constexpr double k = 1; |
| 429 |
}; |
| 430 |
template <typename T, int N> |
| 431 |
struct 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 both |
| 439 |
// the dependent type and non-dependent type versions. |
| 440 |
template <typename T> |
| 441 |
struct 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 |
}; |
| 448 |
template <typename T, int N> |
| 449 |
struct 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 |
}; |
| 456 |
template <typename T> |
| 457 |
struct 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 |
|
| 465 |
template <typename T> |
| 466 |
struct PR45298 { |
| 467 |
T k1 = T(0); |
| 468 |
}; |
| 469 |
|
| 470 |
// Ensure this no longer asserts. |
| 471 |
template <typename T> |
| 472 |
struct PR45298Consumer { |
| 473 |
float4 f(float4 x) { |
| 474 |
return (float)s.k1 * x; |
| 475 |
} |
| 476 |
|
| 477 |
PR45298<T> s; |
| 478 |
}; |
| 479 |
#endif // __cplusplus >= 201103L |
| 480 |
|
| 481 |
void use() { |
| 482 |
float4 theFloat4; |
| 483 |
NormalMember<double>().f(theFloat4); |
| 484 |
#if __cplusplus >= 201103L |
| 485 |
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 >= 201103L |
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
namespace rdar60092165 { |
| 498 |
template <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 |
|
| 506 |
namespace PR45780 { |
| 507 |
enum E { Value = 15 }; |
| 508 |
void 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 PR45780 |
| 517 |
|
| 518 |
namespace PR48540 { |
| 519 |
// The below used to cause an OOM error, or an assert, make sure it is still |
| 520 |
// valid. |
| 521 |
int (__attribute__((vector_size(16))) a); |
| 522 |
|
| 523 |
template <typename T, int I> |
| 524 |
struct S { |
| 525 |
T (__attribute__((vector_size(16))) a); |
| 526 |
int (__attribute__((vector_size(I))) b); |
| 527 |
T (__attribute__((vector_size(I))) c); |
| 528 |
}; |
| 529 |
|
| 530 |
void use() { |
| 531 |
S<int, 16> s; |
| 532 |
} |
| 533 |
} // namespace PR48540 |
| 534 |
|
| 535 |
#if __cplusplus >= 202002L // C++20 or later |
| 536 |
// Don't crash due to missing integer ranks. |
| 537 |
char8_t v1 __attribute__((vector_size(16))); |
| 538 |
char16_t v2 __attribute__((vector_size(16))); |
| 539 |
char32_t v3 __attribute__((vector_size(16))); |
| 540 |
wchar_t v4 __attribute__((vector_size(16))); |
| 541 |
void triggerIntegerRankCheck() { |
| 542 |
auto b1 = (v1 >= 0x12); |
| 543 |
auto b2 = (v2 >= 0x12); |
| 544 |
auto b3 = (v3 >= 0x12); |
| 545 |
auto b4 = (v4 >= 0x12); |
| 546 |
} |
| 547 |
#endif |
| 548 |
|
| 549 |
namespace all_operators { |
| 550 |
typedef unsigned int v2u __attribute__((ext_vector_type(2))); |
| 551 |
typedef float v2f __attribute__((ext_vector_type(2))); |
| 552 |
|
| 553 |
void 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 |
|
| 617 |
void 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 |
|
| 685 |
enum Enum { ENUM }; |
| 686 |
|
| 687 |
void 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 via |
| 691 |
// the enum converting to an integer then splatting to the vector width. |
| 692 |
// https://github.com/llvm/llvm-project/issues/62869 |
| 693 |
(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 failure |
| 732 |
// https://github.com/llvm/llvm-project/issues/62870 |
| 733 |
// (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 failure |
| 747 |
// https://github.com/llvm/llvm-project/issues/62870 |
| 748 |
// 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 failure |
| 760 |
// https://github.com/llvm/llvm-project/issues/62870 |
| 761 |
// 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 later |
| 766 |
enum class EnumClass { ENUM }; |
| 767 |
|
| 768 |
void 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 |
#endif |
| 774 |
} |
| 775 |
|
| 776 |
namespace GH105486 { |
| 777 |
__attribute__((__vector_size__(sizeof(double)))) double a; |
| 778 |
double 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; |
| 782 |
long 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 |
|
| 785 |
const long long e = *0; // expected-error {{indirection requires pointer operand ('int' invalid)}} |
| 786 |
double 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)}} |
| 787 |
int 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 |
|
| 790 |
typedef int v_neg_size __attribute__((vector_size(-8))); // expected-error{{vector must have non-negative size}} |
| 791 |
typedef int v_neg_size_2 __attribute__((vector_size(-1 * 8))); // expected-error{{vector must have non-negative size}} |
| 792 |
typedef int v_ext_neg_size __attribute__((ext_vector_type(-8))); // expected-error{{vector must have non-negative size}} |
| 793 |
typedef int v_ext_neg_size2 __attribute__((ext_vector_type(-1 * 8))); // expected-error{{vector must have non-negative size}} |
| 794 |
|
| 795 |
|
| 796 |
#if __cplusplus >= 201103L |
| 797 |
|
| 798 |
template <int N> using templated_v_size = int __attribute__((vector_size(N))); // expected-error{{vector must have non-negative size}} |
| 799 |
templated_v_size<-8> templated_v_neg_size; //expected-note{{in instantiation of template type alias 'templated_v_size' requested here}} |
| 800 |
|
| 801 |
#endif |
| 802 |
|
| 803 |
namespace GH173347 { |
| 804 |
typedef short __attribute__((__vector_size__(8))) V; |
| 805 |
template <int N> V test(V x) { return (x % 5) * N; } |
| 806 |
} |