From 7fb52af2ec381cc0f02219f0221042786c1f2cbd Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Wed, 27 Feb 2008 13:17:17 +0000 Subject: [PATCH] re PR tree-optimization/25290 (PHI-OPT could be rewritten so that is uses fold) 2008-02-27 Richard Guenther PR middle-end/25290 * fold-const.c (fold_unary): Return the correct argument, converted to the result type. * gcc.c-torture/execute/pr35390.c: New testcase. From-SVN: r132710 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.c-torture/execute/pr35390.c | 13 +++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr35390.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c8e74f5c58a..aff90b89e5d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-02-27 Richard Guenther + + PR middle-end/25290 + * fold-const.c (fold_unary): Return the correct argument, + converted to the result type. + 2008-02-27 Richard Guenther PR middle-end/34971 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index f6a73efe9ad..987acf1649c 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8340,7 +8340,7 @@ fold_unary (enum tree_code code, tree type, tree op0) if (TREE_CODE (arg0) == INTEGER_CST) return fold_not_const (arg0, type); else if (TREE_CODE (arg0) == BIT_NOT_EXPR) - return TREE_OPERAND (op0, 0); + return fold_convert (type, TREE_OPERAND (arg0, 0)); /* Convert ~ (-A) to A - 1. */ else if (INTEGRAL_TYPE_P (type) && TREE_CODE (arg0) == NEGATE_EXPR) return fold_build2 (MINUS_EXPR, type, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8d5fff7cf2b..51196bb03ae 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-02-27 Richard Guenther + + PR middle-end/25290 + * gcc.c-torture/execute/pr35390.c: New testcase. + 2008-02-27 Samuel Tardieu PR ada/22255 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr35390.c b/gcc/testsuite/gcc.c-torture/execute/pr35390.c new file mode 100644 index 00000000000..7103a9b5414 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr35390.c @@ -0,0 +1,13 @@ +extern void abort (void); + +unsigned int foo (int n) +{ + return ~((unsigned int)~n); +} + +int main() +{ + if (foo(0) != 0) + abort (); + return 0; +} -- 2.30.2