From 00cb61524ed17f2116724947bd2516be5fc332d4 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Tue, 25 Mar 2008 10:17:54 +0000 Subject: [PATCH] backport: re PR middle-end/35163 (folding comparison loses cast) 2008-03-25 Richard Guenther Backport from mainline: 2008-02-12 Richard Guenther PR middle-end/35163 * fold-const.c (fold_widened_comparison): Use get_unwidened in value-preserving mode. Disallow final truncation. * gcc.c-torture/execute/pr35163.c: New testcase. From-SVN: r133509 --- gcc/ChangeLog | 9 +++++++++ gcc/fold-const.c | 4 +++- gcc/testsuite/ChangeLog | 8 ++++++++ gcc/testsuite/gcc.c-torture/execute/pr35163.c | 11 +++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr35163.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 46b345352768..9c9783256b06 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2008-03-25 Richard Guenther + + Backport from mainline: + 2008-02-12 Richard Guenther + + PR middle-end/35163 + * fold-const.c (fold_widened_comparison): Use get_unwidened in + value-preserving mode. Disallow final truncation. + 2008-03-05 Kaveh R. Ghazi Backport: diff --git a/gcc/fold-const.c b/gcc/fold-const.c index f9e58d275910..bac759ec053b 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6301,12 +6301,14 @@ fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1) if (TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (shorter_type)) return NULL_TREE; - arg1_unw = get_unwidened (arg1, shorter_type); + arg1_unw = get_unwidened (arg1, NULL_TREE); /* If possible, express the comparison in the shorter mode. */ if ((code == EQ_EXPR || code == NE_EXPR || TYPE_UNSIGNED (TREE_TYPE (arg0)) == TYPE_UNSIGNED (shorter_type)) && (TREE_TYPE (arg1_unw) == shorter_type + || (TYPE_PRECISION (shorter_type) + >= TYPE_PRECISION (TREE_TYPE (arg1_unw))) || (TREE_CODE (arg1_unw) == INTEGER_CST && (TREE_CODE (shorter_type) == INTEGER_TYPE || TREE_CODE (shorter_type) == BOOLEAN_TYPE) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2e831e83f791..4a6e9eb92188 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2008-03-25 Richard Guenther + + Backport from mainline: + 2008-02-12 Richard Guenther + + PR middle-end/35163 + * gcc.c-torture/execute/pr35163.c: New testcase. + 2008-02-13 Kaveh R. Ghazi Backport: diff --git a/gcc/testsuite/gcc.c-torture/execute/pr35163.c b/gcc/testsuite/gcc.c-torture/execute/pr35163.c new file mode 100644 index 000000000000..4950d6d2027d --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr35163.c @@ -0,0 +1,11 @@ +extern void abort(void); + +int main() +{ + signed char a = -30; + signed char b = -31; + if (a > (unsigned short)b) + abort (); + return 0; +} + -- 2.47.2