aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2018-09-12 11:18:55 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2018-09-12 11:18:55 +0200
commit9095b53a8c4a5663b89db946462ff534fe0836e7 (patch)
treeda1ef5ad548d824044517acc96b14c4f5dff6844 /gcc/fold-const.c
parent03e992aceab3207fa92d26c44dd5b4845f1c23ed (diff)
downloadgcc-9095b53a8c4a5663b89db946462ff534fe0836e7.zip
gcc-9095b53a8c4a5663b89db946462ff534fe0836e7.tar.gz
gcc-9095b53a8c4a5663b89db946462ff534fe0836e7.tar.bz2
re PR middle-end/87248 (Bad code for masked operations involving signed ints)
PR middle-end/87248 * fold-const.c (fold_ternary_loc) <case COND_EXPR>: Verify also that BIT_AND_EXPR's second operand is a power of two. Formatting fix. * c-c++-common/torture/pr87248.c: New test. From-SVN: r264230
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index bdd24c5..3bcf272 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -11607,10 +11607,16 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
&& integer_pow2p (arg1)
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == BIT_AND_EXPR
&& operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1),
- arg1, OEP_ONLY_CONST))
+ arg1, OEP_ONLY_CONST)
+ /* operand_equal_p compares just value, not precision, so e.g.
+ arg1 could be 8-bit -128 and be power of two, but BIT_AND_EXPR
+ second operand 32-bit -128, which is not a power of two (or vice
+ versa. */
+ && integer_pow2p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1)))
return pedantic_non_lvalue_loc (loc,
- fold_convert_loc (loc, type,
- TREE_OPERAND (arg0, 0)));
+ fold_convert_loc (loc, type,
+ TREE_OPERAND (arg0,
+ 0)));
/* Disable the transformations below for vectors, since
fold_binary_op_with_conditional_arg may undo them immediately,