This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[trunk][patch] fix a bug in fold_call_expr and one in record_temporary_equivalences_from_stmts_at_dest
- From: "Rafael Espindola" <espindola at google dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Cc: "Diego Novillo" <dnovillo at google dot com>
- Date: Wed, 30 Apr 2008 14:54:13 +0100
- Subject: [trunk][patch] fix a bug in fold_call_expr and one in record_temporary_equivalences_from_stmts_at_dest
There is a missing return in fold_call_expr. This bug disables some
uses of jump threading. In particular, it disables jump threading
based on values returned by __builtin_object_size. This hides another
bug: One cannot use __builtin_object_size in jump threading. The
definition of __builtin_object_size makes its return value depend on
the existence of arguments to a phi node.
The patch fixes both bugs.
OK with a bootstrap and regression tests?
* builtins.c (fold_call_expr): Return realret.
* tree-ssa-threadedge.c
(record_temporary_equivalences_from_stmts_at_dest): Ignore calls to
__builtin_object_size.
Cheers,
--
Rafael Avila de Espindola
Google Ireland Ltd.
Gordon House
Barrow Street
Dublin 4
Ireland
Registered in Dublin, Ireland
Registration Number: 368047
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 321032d..2cb8fa0 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -10553,6 +10553,7 @@ fold_call_expr (tree exp, bool ignore)
if (CAN_HAVE_LOCATION_P (realret)
&& !EXPR_HAS_LOCATION (realret))
SET_EXPR_LOCATION (realret, EXPR_LOCATION (exp));
+ return realret;
}
return ret;
}
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index d0d8fb2..71aa91b 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -226,6 +226,7 @@ record_temporary_equivalences_from_stmts_at_dest (edge e,
for (bsi = bsi_start (e->dest); ! bsi_end_p (bsi); bsi_next (&bsi))
{
tree cached_lhs = NULL;
+ tree rhs;
stmt = bsi_stmt (bsi);
@@ -252,6 +253,18 @@ record_temporary_equivalences_from_stmts_at_dest (edge e,
|| TREE_CODE (GIMPLE_STMT_OPERAND (stmt, 0)) != SSA_NAME)
continue;
+ rhs = GIMPLE_STMT_OPERAND (stmt, 1);
+
+ /* The result of __builtin_object_size depends on all the arguments
+ of a phi node. Temporally using only one edge produces invalid
+ results. */
+ if (TREE_CODE (rhs) == CALL_EXPR)
+ {
+ tree fndecl = get_callee_fndecl (rhs);
+ if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_OBJECT_SIZE)
+ continue;
+ }
+
/* At this point we have a statement which assigns an RHS to an
SSA_VAR on the LHS. We want to try and simplify this statement
to expose more context sensitive equivalences which in turn may
@@ -259,10 +272,10 @@ record_temporary_equivalences_from_stmts_at_dest (edge e,
Handle simple copy operations as well as implied copies from
ASSERT_EXPRs. */
- if (TREE_CODE (GIMPLE_STMT_OPERAND (stmt, 1)) == SSA_NAME)
- cached_lhs = GIMPLE_STMT_OPERAND (stmt, 1);
- else if (TREE_CODE (GIMPLE_STMT_OPERAND (stmt, 1)) == ASSERT_EXPR)
- cached_lhs = TREE_OPERAND (GIMPLE_STMT_OPERAND (stmt, 1), 0);
+ if (TREE_CODE (rhs) == SSA_NAME)
+ cached_lhs = rhs;
+ else if (TREE_CODE (rhs) == ASSERT_EXPR)
+ cached_lhs = TREE_OPERAND (rhs, 0);
else
{
/* A statement that is not a trivial copy or ASSERT_EXPR.