| 1 |
#include <arm_neon.h> |
| 2 |
|
| 3 |
typedef float vecf __attribute__((vector_size(16))); |
| 4 |
|
| 5 |
// This assertion must hold: vecf and float32x4_t have distinct identities |
| 6 |
// and mangle differently, so they are not interchangeable. |
| 7 |
template<typename T> struct bar; |
| 8 |
template<> struct bar<vecf> { static const int x = 1; }; |
| 9 |
template<> struct bar<float32x4_t> { static const int x = 2; }; |
| 10 |
static_assert(bar<vecf>::x + bar<float32x4_t>::x == 3, "boo"); |
| 11 |
|
| 12 |
// GCC 10.1 and earlier accepted this. However, the rule should be |
| 13 |
// that GNU vectors and Advanced SIMD vectors are distinct types but |
| 14 |
// that each one implicitly converts to the other. The types are not |
| 15 |
// reference-compatible. |
| 16 |
// |
| 17 |
// The behavior tested below is consistent with Clang. |
| 18 |
vecf x; |
| 19 |
float32x4_t y; |
| 20 |
float32x4_t &z = x; // { dg-error {cannot bind non-const lvalue reference} } |
| 21 |
|
| 22 |
// These assignment must be valid even in the strictest mode: vecf must |
| 23 |
// implicitly convert to float32x4_t and vice versa. |
| 24 |
void foo() { x = y; y = x; } |
| 25 |
|
| 26 |
// Previously GCC accepted this and took the type of "d" from the "then" arm. |
| 27 |
// It therefore mangled the functions as: |
| 28 |
// |
| 29 |
// _Z4sel1bRDv4_f |
| 30 |
// _Z4sel2bR13__Float32x4_t |
| 31 |
// |
| 32 |
// Clang currently also accepts it and takes the type of "d" from the |
| 33 |
// "else" arm. It therefore mangles the functions as follows, which is |
| 34 |
// inconsistent with the old GCC behavior: |
| 35 |
// |
| 36 |
// _Z4sel1b13__Float32x4_t |
| 37 |
// _Z4sel2bDv4_f |
| 38 |
// |
| 39 |
// Given that the types have distinct identities and that each one |
| 40 |
// implicitly converts to the other (see above), the expression ought |
| 41 |
// to be rejected as invalid. This is consistent (by analogy) with the |
| 42 |
// standard C++ handling of conditional expressions involving class types, |
| 43 |
// in cases where the "then" value implicitly converts to the "else" type |
| 44 |
// and the "else" value implicitly converts to the "then" type. |
| 45 |
auto sel1(bool c, decltype(c ? x : y) d) { return d; } // { dg-error {operands to '\?:' have different types} } |
| 46 |
auto sel2(bool c, decltype(c ? y : x) d) { return d; } // { dg-error {operands to '\?:' have different types} } |