From 4763581763de6049c938ea7129d738d497004a06 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 6 Feb 2019 10:16:19 +0100 Subject: [PATCH] re PR middle-end/89210 (ICE tree check: expected integer_cst, have real_cst in to_wide, at tree.h:5600) PR middle-end/89210 * fold-const-call.c (fold_const_vec_convert): Pass true as last operand to new_unary_operation only if both element types are integral and it isn't a widening conversion. Return NULL_TREE if new_unary_operation failed. * c-c++-common/builtin-convertvector-2.c: New test. From-SVN: r268573 --- gcc/ChangeLog | 8 ++++++++ gcc/fold-const-call.c | 11 ++++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/builtin-convertvector-2.c | 12 ++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/builtin-convertvector-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 137066a52f6..5e2d7e75b4d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2019-02-06 Jakub Jelinek + + PR middle-end/89210 + * fold-const-call.c (fold_const_vec_convert): Pass true as last + operand to new_unary_operation only if both element types are integral + and it isn't a widening conversion. Return NULL_TREE if + new_unary_operation failed. + 2019-02-05 Andreas Krebbel PR target/88856 diff --git a/gcc/fold-const-call.c b/gcc/fold-const-call.c index 439043a85a0..702c8b4057a 100644 --- a/gcc/fold-const-call.c +++ b/gcc/fold-const-call.c @@ -665,8 +665,17 @@ fold_const_vec_convert (tree ret_type, tree arg) && SCALAR_FLOAT_TYPE_P (TREE_TYPE (ret_type))) code = FLOAT_EXPR; + /* We can't handle steps directly when extending, since the + values need to wrap at the original precision first. */ + bool step_ok_p + = (INTEGRAL_TYPE_P (TREE_TYPE (ret_type)) + && INTEGRAL_TYPE_P (TREE_TYPE (arg_type)) + && (TYPE_PRECISION (TREE_TYPE (ret_type)) + <= TYPE_PRECISION (TREE_TYPE (arg_type)))); tree_vector_builder elts; - elts.new_unary_operation (ret_type, arg, true); + if (!elts.new_unary_operation (ret_type, arg, step_ok_p)) + return NULL_TREE; + unsigned int count = elts.encoded_nelts (); for (unsigned int i = 0; i < count; ++i) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0dd171c9647..b5c92ffb6b6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-02-06 Jakub Jelinek + + PR middle-end/89210 + * c-c++-common/builtin-convertvector-2.c: New test. + 2019-02-05 Nikhil Benesch PR go/89019 diff --git a/gcc/testsuite/c-c++-common/builtin-convertvector-2.c b/gcc/testsuite/c-c++-common/builtin-convertvector-2.c new file mode 100644 index 00000000000..ee77c79fa8e --- /dev/null +++ b/gcc/testsuite/c-c++-common/builtin-convertvector-2.c @@ -0,0 +1,12 @@ +/* PR middle-end/89210 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +typedef int v4si __attribute__((vector_size (4 * sizeof (int)))); +typedef double v4df __attribute__((vector_size (4 * sizeof (double)))); +void +foo (v4df *x) +{ + v4si a = { 1, 2, 3, 4 }; + *x = __builtin_convertvector (a, v4df); +} -- 2.30.2