Submitted By: Jim Gifford (patches at jg555 dot com) Date: 2006-04-17 Initial Package Version: 4.1.0 Origin: Maintainers Upstream Status: Fixed in SVN Description: Fixes an optimization error that can result incorrectly code. See PR's below Issues in CLFS book, this patch fixes the incorrect disk checksums in silo. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27176 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26763 diff -Naur gcc-4.1.0.orig/ChangeLog gcc-4.1.0/ChangeLog --- gcc-4.1.0.orig/ChangeLog 2006-02-28 08:30:33.000000000 +0000 +++ gcc-4.1.0/ChangeLog 2006-04-17 19:32:36.000000000 +0000 @@ -1,3 +1,12 @@ +2006-04-05 Richard Guenther + + PR tree-optimization/26763 + * fold-const.c (fold_binary): Fold PTR + CST CMP PTR + CST + only for EQ_EXPR and NE_EXPR. + + * gcc.dg/torture/pr26763-1.c: New testcase. + * gcc.dg/torture/pr26763-2.c: Likewise. + 2006-02-28 Release Manager * GCC 4.1.0 released. diff -Naur gcc-4.1.0.orig/gcc/fold-const.c gcc-4.1.0/gcc/fold-const.c --- gcc-4.1.0.orig/gcc/fold-const.c 2006-02-03 18:02:04.000000000 +0000 +++ gcc-4.1.0/gcc/fold-const.c 2006-04-17 19:33:55.000000000 +0000 @@ -8897,8 +8897,9 @@ /* If this is a comparison of two exprs that look like an ARRAY_REF of the same object, then we can fold this to a - comparison of the two offsets. */ - if (TREE_CODE_CLASS (code) == tcc_comparison) + comparison of the two offsets. This is only safe for + EQ_EXPR and NE_EXPR because of overflow issues. */ + if (code == EQ_EXPR || code == NE_EXPR) { tree base0, offset0, base1, offset1; diff -Naur gcc-4.1.0.orig/gcc/testsuite/ChangeLog gcc-4.1.0/gcc/testsuite/ChangeLog --- gcc-4.1.0.orig/gcc/testsuite/ChangeLog 2006-02-28 08:27:59.000000000 +0000 +++ gcc-4.1.0/gcc/testsuite/ChangeLog 2006-04-17 19:35:18.000000000 +0000 @@ -1,3 +1,12 @@ +2006-04-05 Richard Guenther + + PR tree-optimization/26763 + * fold-const.c (fold_binary): Fold PTR + CST CMP PTR + CST + only for EQ_EXPR and NE_EXPR. + + * gcc.dg/torture/pr26763-1.c: New testcase. + * gcc.dg/torture/pr26763-2.c: Likewise. + 2006-02-28 Release Manager * GCC 4.1.0 released. diff -Naur gcc-4.1.0.orig/gcc/testsuite/gcc.dg/pr26763-1.ch gcc-4.1.0/gcc/testsuite/gcc.dg/pr26763-1.ch --- gcc-4.1.0.orig/gcc/testsuite/gcc.dg/pr26763-1.ch 1970-01-01 00:00:00.000000000 +0000 +++ gcc-4.1.0/gcc/testsuite/gcc.dg/pr26763-1.ch 2006-04-17 19:36:55.000000000 +0000 @@ -0,0 +1,18 @@ +/* { dg-do run } */ + +extern void abort(void); + +int try (int *a) +{ + return a + -1 > a; +} + +int main(void) +{ + int bla[100]; + + if (try (bla + 50)) + abort (); + + return 0; +} diff -Naur gcc-4.1.0.orig/gcc/testsuite/gcc.dg/pr26763-2.c gcc-4.1.0/gcc/testsuite/gcc.dg/pr26763-2.c --- gcc-4.1.0.orig/gcc/testsuite/gcc.dg/pr26763-2.c 1970-01-01 00:00:00.000000000 +0000 +++ gcc-4.1.0/gcc/testsuite/gcc.dg/pr26763-2.c 2006-04-17 19:37:11.000000000 +0000 @@ -0,0 +1,18 @@ +/* { dg-do run } */ + +extern void abort(void); + +int try (char *a, int d) +{ + return a + d > a; +} + +int main(void) +{ + char bla[100]; + + if (try (bla + 50, -1)) + abort (); + + return 0; +}