2010-11-11 Jakub Jelinek Backport from mainline 2010-11-03 Jakub Jelinek PR tree-optimization/46165 * tree-ssa-pre.c (eliminate): Return TODO_cleanup_cfg if changing a normal call into noreturn call. * gcc.dg/pr46165.c: New test. --- gcc/tree-ssa-pre.c (revision 166235) +++ gcc/tree-ssa-pre.c (revision 166236) @@ -4311,6 +4311,8 @@ eliminate (void) && TREE_CODE (gimple_call_fn (stmt)) == SSA_NAME) { tree fn = VN_INFO (gimple_call_fn (stmt))->valnum; + bool was_noreturn = gimple_call_noreturn_p (stmt); + if (TREE_CODE (fn) == ADDR_EXPR && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL) { @@ -4324,6 +4326,12 @@ eliminate (void) gimple_call_set_fn (stmt, fn); update_stmt (stmt); + + /* When changing a call into a noreturn call, cfg cleanup + is needed to fix up the noreturn call. */ + if (!was_noreturn && gimple_call_noreturn_p (stmt)) + todo |= TODO_cleanup_cfg; + if (maybe_clean_or_replace_eh_stmt (stmt, stmt)) { bitmap_set_bit (need_eh_cleanup, --- gcc/testsuite/gcc.dg/pr46165.c (revision 0) +++ gcc/testsuite/gcc.dg/pr46165.c (revision 166236) @@ -0,0 +1,11 @@ +/* PR tree-optimization/46165 */ +/* { dg-do compile } */ +/* { dg-options "-O -fno-tree-ccp -fno-tree-copy-prop -fno-tree-dce" } */ + +extern void foo (void) __attribute__((noreturn)); +void +g (void) +{ + void (*f) (void) = foo; + f (); +}