diff options
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/fold-const.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/20080813-1.c | 30 |
4 files changed, 43 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2b4062a..ed3129d 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 cae45b5..eac31ef 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 f4d6909..ca3aa251 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 0000000..9ef6bc2 --- /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; +} |