[PATCH] c++: ICE when shortening right shift [PR94955]
Jason Merrill
jason@redhat.com
Mon May 18 22:40:31 GMT 2020
On 5/6/20 4:31 PM, Marek Polacek wrote:
> Since r10-6527 fold_for_warn calls maybe_constant_value, which means it
> can fold more than it previously could. In this testcase it means that
> cp_build_binary_op/RSHIFT_EXPR set short_shift because now we were able
> to fold op1 to an INTEGER_CST. But then when actually performing the
> shortening we crashed because cp_fold_rvalue wasn't able to fold as much
> as f_f_w and so tree_int_cst_sgn crashed on a NOP_EXPR. Therefore the
> calls should probably match.
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/10.2?
OK.
> PR c++/94955
> * typeck.c (cp_build_binary_op): Use fold_for_warn instead of
> cp_fold_rvalue.
>
> * g++.dg/cpp0x/constexpr-shift2.C: New test.
> ---
> gcc/cp/typeck.c | 4 +++-
> gcc/testsuite/g++.dg/cpp0x/constexpr-shift2.C | 12 ++++++++++++
> 2 files changed, 15 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-shift2.C
>
> diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
> index 8e3188a415d..b468e92896a 100644
> --- a/gcc/cp/typeck.c
> +++ b/gcc/cp/typeck.c
> @@ -5606,7 +5606,9 @@ cp_build_binary_op (const op_location_t &location,
> {
> int unsigned_arg;
> tree arg0 = get_narrower (op0, &unsigned_arg);
> - tree const_op1 = cp_fold_rvalue (op1);
> + /* We're not really warning here but when we set short_shift we
> + used fold_for_warn to fold the operand. */
> + tree const_op1 = fold_for_warn (op1);
>
> final_type = result_type;
>
> diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-shift2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-shift2.C
> new file mode 100644
> index 00000000000..9b3490a66a7
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-shift2.C
> @@ -0,0 +1,12 @@
> +// PR c++/94955
> +// { dg-do compile { target c++11 } }
> +
> +struct S {
> + static constexpr char foo() { return 10; }
> +};
> +
> +short int
> +fn (short int e)
> +{
> + return e >> S::foo();
> +}
>
> base-commit: 319eafce3e54c8cb10e3fddce6823a6a558fca8b
>
More information about the Gcc-patches
mailing list