middle-end/112622 - convert and vector-to-float
Checks
Commit Message
The following avoids ICEing when trying to convert a vector to
a scalar float.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR middle-end/112622
* convert.cc (convert_to_real_1): Use element_precision
where a vector type might appear. Provide specific
diagnostic for unexpected vector argument.
* gcc.dg/pr112622.c: New testcase.
---
gcc/convert.cc | 6 +++++-
gcc/testsuite/gcc.dg/pr112622.c | 5 +++++
gcc/testsuite/gcc.dg/simd-2.c | 4 ++--
gcc/testsuite/gcc.target/i386/vect-bfloat16-typecheck_1.c | 8 ++++----
gcc/testsuite/gcc.target/i386/vect-bfloat16-typecheck_2.c | 8 ++++----
5 files changed, 20 insertions(+), 11 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/pr112622.c
@@ -292,7 +292,7 @@ convert_to_real_1 (tree type, tree expr, bool fold_p)
case NEGATE_EXPR:
if (!flag_rounding_math
&& FLOAT_TYPE_P (itype)
- && TYPE_PRECISION (type) < TYPE_PRECISION (itype))
+ && element_precision (type) < element_precision (itype))
{
tree arg = convert_to_real_1 (type, TREE_OPERAND (expr, 0),
fold_p);
@@ -334,6 +334,10 @@ convert_to_real_1 (tree type, tree expr, bool fold_p)
error ("pointer value used where a floating-point was expected");
return error_mark_node;
+ case VECTOR_TYPE:
+ error ("vector value used where a floating-point was expected");
+ return error_mark_node;
+
default:
error ("aggregate value used where a floating-point was expected");
return error_mark_node;
new file mode 100644
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+
+typedef __attribute__((__vector_size__(4))) float V;
+
+V v = (float)-v; /* { dg-error "vector value used" } */
@@ -33,10 +33,10 @@ hanneke ()
foo = a; /* { dg-error "incompatible types when assigning" } */
/* Casted assignment between scalar and SIMD of same size. */
- foo = (typeof (foo)) foo2; /* { dg-error "aggregate value used where a floating-point was expected" } */
+ foo = (typeof (foo)) foo2; /* { dg-error "vector value used where a floating-point was expected" } */
/* Casted assignment between scalar and SIMD of different size. */
- foo1 = (typeof (foo1)) foo2; /* { dg-error "aggregate value used where a floating-point was expected" } */
+ foo1 = (typeof (foo1)) foo2; /* { dg-error "vector value used where a floating-point was expected" } */
/* Operators on compatible SIMD types. */
a += b + b;
@@ -123,12 +123,12 @@ __m128bf16 footest (__m128bf16 vector0)
(void) glob_bfloat_vec;
(__m128bf16) glob_bfloat_vec;
- (__bf16) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */
+ (__bf16) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */
(short) glob_bfloat_vec; /* { dg-error {cannot convert a vector of type '__m128bf16' {aka '__vector\(8\) __bf16'} to type 'short int' which has different size} } */
(int) glob_bfloat_vec; /* { dg-error {cannot convert a vector of type '__m128bf16' {aka '__vector\(8\) __bf16'} to type 'int' which has different size} } */
- (_Float16) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */
- (float) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */
- (double) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */
+ (_Float16) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */
+ (float) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */
+ (double) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */
(__v8si) glob_bfloat_vec; /* { dg-error {cannot convert a value of type '__m128bf16' {aka '__vector\(8\) __bf16'} to vector type '__vector\(8\) int' which has different size} } */
(__m256) glob_bfloat_vec; /* { dg-error {cannot convert a value of type '__m128bf16' {aka '__vector\(8\) __bf16'} to vector type '__vector\(8\) float' which has different size} } */
@@ -116,12 +116,12 @@ __m256bf16 footest (__m256bf16 vector0)
(void) glob_bfloat_vec;
(__m256bf16) glob_bfloat_vec;
- (__bf16) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */
+ (__bf16) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */
(short) glob_bfloat_vec; /* { dg-error {cannot convert a vector of type '__m256bf16' {aka '__vector\(16\) __bf16'} to type 'short int' which has different size} } */
(int) glob_bfloat_vec; /* { dg-error {cannot convert a vector of type '__m256bf16' {aka '__vector\(16\) __bf16'} to type 'int' which has different size} } */
- (_Float16) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */
- (float) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */
- (double) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */
+ (_Float16) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */
+ (float) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */
+ (double) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */
(__v8si) glob_bfloat_vec;
(__m256) glob_bfloat_vec;