This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix 23476
- From: Diego Novillo <dnovillo at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 19 Aug 2005 09:39:57 -0400
- Subject: Fix 23476
When cleanup_control_expr_graph evaluates a conditional
predicate, it just takes the predicate and compares it against a
constant value.
However, it never calls fold() on it, so if the predicate is of
the form 'if (int_var > INT_MAX)', it doesn't realize that the
predicate is always false.
This was causing VRP to insert trivially false assertions, which
were caught during assertion removal. Besides, it was leaving
trivially unreachable basic blocks around for optimizers to waste
their time with.
Bootstrap and testing in progress.
PR 23476
* tree-cfgcleanup.c (cleanup_control_expr_graph): Fold the
conditional expression before testing its value.
PR 23476
* gcc.c-torture/compile/pr23476.c: New test.
Index: tree-cfgcleanup.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfgcleanup.c,v
retrieving revision 2.5
diff -d -u -p -r2.5 tree-cfgcleanup.c
--- tree-cfgcleanup.c 2 Aug 2005 19:12:41 -0000 2.5
+++ tree-cfgcleanup.c 19 Aug 2005 13:29:37 -0000
@@ -81,11 +81,11 @@ cleanup_control_expr_graph (basic_block
switch (TREE_CODE (expr))
{
case COND_EXPR:
- val = COND_EXPR_COND (expr);
+ val = fold (COND_EXPR_COND (expr));
break;
case SWITCH_EXPR:
- val = SWITCH_COND (expr);
+ val = fold (SWITCH_COND (expr));
if (TREE_CODE (val) != INTEGER_CST)
return false;
break;
Index: testsuite/gcc.c-torture/compile/pr23476.c
===================================================================
RCS file: testsuite/gcc.c-torture/compile/pr23476.c
diff -N testsuite/gcc.c-torture/compile/pr23476.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.c-torture/compile/pr23476.c 19 Aug 2005 13:29:38 -0000
@@ -0,0 +1,14 @@
+int h(int);
+int t;
+static inline int f(const int i)
+{
+ int tt = i;
+ _Bool a = i < t;
+ if (a)
+ return h(t);
+ return 9;
+}
+int g(void)
+{
+ return f(0x7FFFFFFF);
+}