Debian Codegraph @

gcc/testsuite/g++.target/arm/pr95726.C

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