From: Richard Guenther Date: Thu, 8 Jun 2006 08:49:19 +0000 (+0000) Subject: re PR middle-end/27116 (Incorrect integer division (wrong sign).) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=960f80d1ee2d882f29886db66a3edf4c824eeaf0;p=gcc.git re PR middle-end/27116 (Incorrect integer division (wrong sign).) 2006-06-08 Richard Guenther 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ea88049fbd1..12bd4194eb9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2006-06-08 Richard Guenther + + 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. + 2006-06-07 Zdenek Dvorak PR tree-optimization/27872 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 6f19704a8f6..3e9ccbe4f66 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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 78cbebc233f..cfeeaeb83e2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2006-06-08 Richard Guenther + + PR middle-end/27116 + * gcc.dg/torture/pr27116.c: New testcase. + * gcc.dg/pr15785-1.c: Remove test for invalid transformation. + 2006-06-07 Zdenek Dvorak PR rtl-optimization/26449 diff --git a/gcc/testsuite/gcc.dg/pr15785-1.c b/gcc/testsuite/gcc.dg/pr15785-1.c index 47cd3d7b01b..5e79ec50bbb 100644 --- a/gcc/testsuite/gcc.dg/pr15785-1.c +++ b/gcc/testsuite/gcc.dg/pr15785-1.c @@ -11,11 +11,6 @@ void b (int x) { link_error (); } -void c (int x) { - if (!(- (~x) - x)) - link_error (); -} - void d (int x) { if (!(~ (-x) - x)) link_error (); @@ -34,7 +29,6 @@ void f (int x) { int main (int argc, char *argv[]) { a(argc); b(argc); - c(argc); d(argc); e(argc); f(argc); diff --git a/gcc/testsuite/gcc.dg/torture/pr27116.c b/gcc/testsuite/gcc.dg/torture/pr27116.c new file mode 100644 index 00000000000..70eeb1a8698 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr27116.c @@ -0,0 +1,15 @@ +/* { dg-do run } */ + +extern void abort(void); + +int f(int a, int b) +{ + return (-1 - a) / (-b); +} + +int main() +{ + if (f(__INT_MAX__, 2) != __INT_MAX__/2 + 1) + abort (); + return 0; +}