diff options
author | Richard Guenther <rguenther@suse.de> | 2006-06-08 08:49:19 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2006-06-08 08:49:19 +0000 |
commit | 960f80d1ee2d882f29886db66a3edf4c824eeaf0 (patch) | |
tree | 4bf8760f5ecfc126786bc6da8fd99de0bb85f219 /gcc/fold-const.c | |
parent | 8e08deebfccb960a2bdbd9c7e30a9e3c4633e12d (diff) | |
download | gcc-960f80d1ee2d882f29886db66a3edf4c824eeaf0.zip gcc-960f80d1ee2d882f29886db66a3edf4c824eeaf0.tar.gz gcc-960f80d1ee2d882f29886db66a3edf4c824eeaf0.tar.bz2 |
re PR middle-end/27116 (Incorrect integer division (wrong sign).)
2006-06-08 Richard Guenther <rguenther@suse.de>
PR middle-end/27116
* fold-const.c (negate_expr_p): We can negate BIT_NOT_EXPR
only, if overflow is defined and not trapping.
(negate_expr): Likewise.
* gcc.dg/torture/pr27116.c: New testcase.
* gcc.dg/pr15785-1.c: Remove test for invalid transformation.
From-SVN: r114483
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 6f19704..3e9ccbe 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -945,7 +945,9 @@ negate_expr_p (tree t) /* Check that -CST will not overflow type. */ return may_negate_without_overflow_p (t); case BIT_NOT_EXPR: - return INTEGRAL_TYPE_P (type); + return INTEGRAL_TYPE_P (type) + && (TYPE_UNSIGNED (type) + || (flag_wrapv && !flag_trapv)); case REAL_CST: case NEGATE_EXPR: @@ -1047,7 +1049,9 @@ negate_expr (tree t) { /* Convert - (~A) to A + 1. */ case BIT_NOT_EXPR: - if (INTEGRAL_TYPE_P (type)) + if (INTEGRAL_TYPE_P (type) + && (TYPE_UNSIGNED (type) + || (flag_wrapv && !flag_trapv))) return fold_build2 (PLUS_EXPR, type, TREE_OPERAND (t, 0), build_int_cst (type, 1)); break; |