aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRoger Sayle <roger@eyesopen.com>2007-03-04 19:03:13 +0000
committerRoger Sayle <sayle@gcc.gnu.org>2007-03-04 19:03:13 +0000
commit270d43bf1ef449e769758eed4fd3c8e02ddac1ec (patch)
treea609ca95a2be9b1ca5061bfa82fdba65079759d8 /gcc/fold-const.c
parent3af836867fc2213cd3b93ced426ba2d5ffc55e9a (diff)
downloadgcc-270d43bf1ef449e769758eed4fd3c8e02ddac1ec.zip
gcc-270d43bf1ef449e769758eed4fd3c8e02ddac1ec.tar.gz
gcc-270d43bf1ef449e769758eed4fd3c8e02ddac1ec.tar.bz2
re PR middle-end/30744 (ICE in compare_values, at tree-vrp.c:466)
PR middle-end/30744 * fold-const.c (fold_comparison): Enforce type consistency when transforming ~X op ~Y to Y op X, and ~X op C to X op' ~C. * gcc.dg/pr30744-1.c: New test case. From-SVN: r122531
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index c8e2f51..dab2647 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8921,16 +8921,23 @@ fold_comparison (enum tree_code code, tree type, tree op0, tree op1)
/* Fold ~X op ~Y as Y op X. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& TREE_CODE (arg1) == BIT_NOT_EXPR)
- return fold_build2 (code, type,
- TREE_OPERAND (arg1, 0),
- TREE_OPERAND (arg0, 0));
+ {
+ tree cmp_type = TREE_TYPE (TREE_OPERAND (arg0, 0));
+ return fold_build2 (code, type,
+ fold_convert (cmp_type, TREE_OPERAND (arg1, 0)),
+ TREE_OPERAND (arg0, 0));
+ }
/* Fold ~X op C as X op' ~C, where op' is the swapped comparison. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& TREE_CODE (arg1) == INTEGER_CST)
- return fold_build2 (swap_tree_comparison (code), type,
- TREE_OPERAND (arg0, 0),
- fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg1), arg1));
+ {
+ tree cmp_type = TREE_TYPE (TREE_OPERAND (arg0, 0));
+ return fold_build2 (swap_tree_comparison (code), type,
+ TREE_OPERAND (arg0, 0),
+ fold_build1 (BIT_NOT_EXPR, cmp_type,
+ fold_convert (cmp_type, arg1)));
+ }
return NULL_TREE;
}