From 2e1d24744be9f2f3a5d0d80c86c4405805daefb5 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek <jakub@redhat.com> Date: Thu, 14 Aug 2008 11:02:46 +0200 Subject: [PATCH] re PR middle-end/37103 (possible integer codegen bug) PR middle-end/37103 * fold-const.c (fold_widened_comparison): Do not allow sign changes that change the result even if shorter type is wider than arg1_unw's type. * gcc.c-torture/execute/20080813-1.c: New test. From-SVN: r139093 --- gcc/ChangeLog | 7 +++++ gcc/fold-const.c | 4 +-- gcc/testsuite/ChangeLog | 5 ++++ .../gcc.c-torture/execute/20080813-1.c | 30 +++++++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/20080813-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2b4062aeae37..ed3129dc38be 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2008-08-14 Jakub Jelinek <jakub@redhat.com> + + PR middle-end/37103 + * fold-const.c (fold_widened_comparison): Do not allow + sign changes that change the result even if shorter type + is wider than arg1_unw's type. + 2008-08-13 Kazu Hirata <kazu@codesourcery.com> * gcc.dg/arm-g2.c, gcc.dg/arm-mmx-1.c, gcc.dg/arm-scd42-2.c: diff --git a/gcc/fold-const.c b/gcc/fold-const.c index cae45b5a6585..eac31ef1a794 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6733,10 +6733,8 @@ fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1) 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))) || ((TYPE_PRECISION (shorter_type) - == TYPE_PRECISION (TREE_TYPE (arg1_unw))) + >= TYPE_PRECISION (TREE_TYPE (arg1_unw))) && (TYPE_UNSIGNED (shorter_type) == TYPE_UNSIGNED (TREE_TYPE (arg1_unw)))) || (TREE_CODE (arg1_unw) == INTEGER_CST diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f4d6909f93d5..ca3aa25161e6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-08-14 Jakub Jelinek <jakub@redhat.com> + + PR middle-end/37103 + * gcc.c-torture/execute/20080813-1.c: New test. + 2008-08-13 H.J. Lu <hongjiu.lu@intel.com> * gcc.target/i386/incoming-1.c: Skip *-*-darwin*. diff --git a/gcc/testsuite/gcc.c-torture/execute/20080813-1.c b/gcc/testsuite/gcc.c-torture/execute/20080813-1.c new file mode 100644 index 000000000000..9ef6bc2e2c55 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/20080813-1.c @@ -0,0 +1,30 @@ +/* PR middle-end/37103 */ + +extern void abort (void); + +void +foo (unsigned short x) +{ + signed char y = -1; + if (x == y) + abort (); +} + +void +bar (unsigned short x) +{ + unsigned char y = -1; + if (x == y) + abort (); +} + +int +main (void) +{ + if (sizeof (int) == sizeof (short)) + return 0; + foo (-1); + if (sizeof (short) > 1) + bar (-1); + return 0; +} -- GitLab