diff options
author | Jason Merrill <jason@redhat.com> | 2020-01-12 15:09:22 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2020-01-13 12:50:12 -0500 |
commit | f1acad4e43908e90ca2b5155a878639cbea4c4e1 (patch) | |
tree | b52d55f016950df1910681d29276aefb356f7195 /gcc/cp | |
parent | 33742a0a02581e518ea238e3136d96c7eda12ccc (diff) | |
download | gcc-f1acad4e43908e90ca2b5155a878639cbea4c4e1.zip gcc-f1acad4e43908e90ca2b5155a878639cbea4c4e1.tar.gz gcc-f1acad4e43908e90ca2b5155a878639cbea4c4e1.tar.bz2 |
PR c++/93238 - short right-shift with enum.
My earlier patch to reintroduce short_shift failed to adjust for the C++
front end use of const_op1 rather than op1.
* typeck.c (cp_build_binary_op): Use folded op1 for short_shift.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 8 |
2 files changed, 10 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1dad238..9b226b8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2020-01-13 Jason Merrill <jason@redhat.com> + + PR c++/93238 - short right-shift with enum. + * typeck.c (cp_build_binary_op): Use folded op1 for short_shift. + 2020-01-10 Jason Merrill <jason@redhat.com> * typeck.c (cp_build_binary_op): Restore short_shift code. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 7b653ceb..8955442 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4848,7 +4848,7 @@ cp_build_binary_op (const op_location_t &location, } else { - if (!integer_zerop (op1)) + if (!integer_zerop (const_op1)) short_shift = 1; if (compare_tree_int (const_op1, TYPE_PRECISION (type0)) >= 0 @@ -5599,6 +5599,7 @@ 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); final_type = result_type; @@ -5606,10 +5607,11 @@ cp_build_binary_op (const op_location_t &location, unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0)); if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type) - && tree_int_cst_sgn (op1) > 0 + && tree_int_cst_sgn (const_op1) > 0 /* We can shorten only if the shift count is less than the number of bits in the smaller type size. */ - && compare_tree_int (op1, TYPE_PRECISION (TREE_TYPE (arg0))) < 0 + && compare_tree_int (const_op1, + TYPE_PRECISION (TREE_TYPE (arg0))) < 0 /* We cannot drop an unsigned shift after sign-extension. */ && (!TYPE_UNSIGNED (final_type) || unsigned_arg)) { |