From 2a8db7532fbfe5aaeb7281c16e5ed9e35622f7cb Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Mon, 29 Jun 2009 14:52:20 +0000 Subject: [PATCH] re PR tree-optimization/40579 (gcc -O2 optimization causes infinite loop and wrong output) 2009-06-29 Richard Guenther PR tree-optimization/40579 * tree-vrp.c (vrp_evaluate_conditional_warnv): Bail out early if the IL to simplify has constants that overflowed. * gcc.c-torture/execute/pr40579.c: New testcase. From-SVN: r149052 --- gcc/ChangeLog | 6 ++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.c-torture/execute/pr40579.c | 28 +++++++++++++++++++ gcc/tree-vrp.c | 8 ++++++ 4 files changed, 47 insertions(+) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr40579.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a1763870e0df..63ca404ef9ce 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2009-06-29 Richard Guenther + + PR tree-optimization/40579 + * tree-vrp.c (vrp_evaluate_conditional_warnv): Bail out early if + the IL to simplify has constants that overflowed. + 2009-06-28 Uros Bizjak PR tree-optimization/40550 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c5d17fef3798..d3ec47688058 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-06-29 Richard Guenther + + PR tree-optimization/40579 + * gcc.c-torture/execute/pr40579.c: New testcase. + 2009-06-28 Uros Bizjak PR tree-optimization/40550 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr40579.c b/gcc/testsuite/gcc.c-torture/execute/pr40579.c new file mode 100644 index 000000000000..7f44af310e7b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr40579.c @@ -0,0 +1,28 @@ +extern void abort (void); +static char * __attribute__((noinline)) +itos(int num) +{ + return (char *)0; +} +static void __attribute__((noinline)) +foo(int i, const char *x) +{ + if (i >= 4) + abort (); +} +int main() +{ + int x = -__INT_MAX__ + 3; + int i; + + for (i = 0; i < 4; ++i) + { + char *p; + --x; + p = itos(x); + foo(i, p); + } + + return 0; +} + diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 4a20c74738ec..53f910d97d65 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -4989,6 +4989,14 @@ vrp_evaluate_conditional_warnv (tree cond, bool use_equiv_p, tree op0 = TREE_OPERAND (cond, 0); tree op1 = TREE_OPERAND (cond, 1); + /* Some passes and foldings leak constants with overflow flag set + into the IL. Avoid doing wrong things with these and bail out. */ + if ((TREE_CODE (op0) == INTEGER_CST + && TREE_OVERFLOW (op0)) + || (TREE_CODE (op1) == INTEGER_CST + && TREE_OVERFLOW (op1))) + return NULL_TREE; + /* We only deal with integral and pointer types. */ if (!INTEGRAL_TYPE_P (TREE_TYPE (op0)) && !POINTER_TYPE_P (TREE_TYPE (op0))) -- 2.47.2