re PR tree-optimization/42231 (Wrong generated code when using a callback function (possible callback function inlining bug ?))

2009-12-27  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/42231
	* ipa-cp.c (ipcp_update_cloned_node): Add missing edges manually
	instead of relying on rebuild_cgraph_edges and mark them as
	indirect calls.
	(ipcp_update_callgraph): Always redirect indirect edges.

	* testsuite/gcc.c-torture/execute/pr42231.c: New test.

From-SVN: r155481
This commit is contained in:
Martin Jambor 2009-12-27 23:39:58 +01:00 committed by Martin Jambor
parent ce63852143
commit c9f8846db8
4 changed files with 74 additions and 2 deletions

View File

@ -1,3 +1,11 @@
2009-12-27 Martin Jambor <mjambor@suse.cz>
PR tree-optimization/42231
* ipa-cp.c (ipcp_update_cloned_node): Add missing edges manually
instead of relying on rebuild_cgraph_edges and mark them as
indirect calls.
(ipcp_update_callgraph): Always redirect indirect edges.
2009-12-23 Jakub Jelinek <jakub@redhat.com>
PR rtl-optimization/42475

View File

@ -191,10 +191,32 @@ ipcp_analyze_node (struct cgraph_node *node)
static void
ipcp_update_cloned_node (struct cgraph_node *new_node)
{
basic_block bb;
gimple_stmt_iterator gsi;
/* We might've introduced new direct calls. */
push_cfun (DECL_STRUCT_FUNCTION (new_node->decl));
current_function_decl = new_node->decl;
rebuild_cgraph_edges ();
FOR_EACH_BB (bb)
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
{
gimple stmt = gsi_stmt (gsi);
tree decl;
if (is_gimple_call (stmt)
&& (decl = gimple_call_fndecl (stmt))
&& !cgraph_edge (new_node, stmt))
{
struct cgraph_edge *new_edge;
new_edge = cgraph_create_edge (new_node, cgraph_node (decl), stmt,
bb->count,
compute_call_stmt_bb_frequency (bb),
bb->loop_depth);
new_edge->indirect_call = 1;
}
}
/* Indirect inlinng rely on fact that we've already analyzed
the body.. */
@ -960,7 +982,9 @@ ipcp_update_callgraph (void)
for (cs = node->callers; cs; cs = next)
{
next = cs->next_caller;
if (ipcp_node_is_clone (cs->caller) || !ipcp_need_redirect_p (cs))
if (!cs->indirect_call
&& (ipcp_node_is_clone (cs->caller)
|| !ipcp_need_redirect_p (cs)))
{
gimple new_stmt;
gimple_stmt_iterator gsi;

View File

@ -1,3 +1,8 @@
2009-12-27 Martin Jambor <mjambor@suse.cz>
PR tree-optimization/42231
* gcc.c-torture/execute/pr42231.c: New test.
2009-12-22 Jason Merrill <jason@redhat.com>
PR c++/42331

View File

@ -0,0 +1,35 @@
extern void abort (void);
static max;
static void __attribute__((noinline)) storemax (int i)
{
if (i > max)
max = i;
}
static int CallFunctionRec(int (*fun)(int depth), int depth) {
if (!fun(depth)) {
return 0;
}
if (depth < 10) {
CallFunctionRec(fun, depth + 1);
}
return 1;
}
static int CallFunction(int (*fun)(int depth)) {
return CallFunctionRec(fun, 1) && !fun(0);
}
static int callback(int depth) {
storemax (depth);
return depth != 0;
}
int main() {
CallFunction(callback);
if (max != 10)
abort ();
return 0;
}