This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PR19578: noreturn vs. function pointer propagation part 2
- From: Richard Sandiford <rsandifo at redhat dot com>
- To: Diego Novillo <dnovillo at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 26 Jan 2005 22:28:01 +0000
- Subject: PR19578: noreturn vs. function pointer propagation part 2
- References: <87wtu5dbdb.fsf@redhat.com> <41F27889.1050102@redhat.com>
Diego Novillo <dnovillo@redhat.com> writes:
> When building the flowgraph, consider indirect calls block
> terminators. It's probably the easiest approach, but it may have a
> negative impact on some codes with many indirect calls (see
> stmt_ends_bb_p).
OK, the patch below does that... kind of. It actually changes
is_ctrl_altering_stmt (the predicate used by stmt_ends_bb_p)
so that indirect calls are conservatively treated as being
control-altering.
Bootstrapped & regression tested on i686-pc-linux-gnu. OK to install?
Richard
PR tree-optimization/19578
* tree-cfg.c (is_ctrl_altering_stmt): Return true for indirect calls.
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.147
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r2.147 tree-cfg.c
--- tree-cfg.c 22 Jan 2005 17:52:36 -0000 2.147
+++ tree-cfg.c 26 Jan 2005 17:07:31 -0000
@@ -2570,7 +2570,7 @@ is_ctrl_stmt (tree t)
bool
is_ctrl_altering_stmt (tree t)
{
- tree call;
+ tree call, decl;
gcc_assert (t);
call = get_call_expr_in (t);
@@ -2581,8 +2581,10 @@ is_ctrl_altering_stmt (tree t)
if (TREE_SIDE_EFFECTS (call) && current_function_has_nonlocal_label)
return true;
- /* A CALL_EXPR also alters control flow if it does not return. */
- if (call_expr_flags (call) & ECF_NORETURN)
+ /* A CALL_EXPR also alters control flow if it does not return,
+ or if we might decide later that it does not return. */
+ decl = get_callee_fndecl (call);
+ if (decl == NULL || (flags_from_decl_or_type (decl) & ECF_NORETURN) != 0)
return true;
}
diff -u /dev/null testsuite/gcc.c-torture/compile/20050124-1.c
--- /dev/null Fri Apr 23 00:21:55 2004
+++ testsuite/gcc.c-torture/compile/20050124-1.c Wed Jan 26 17:07:03 2005
@@ -0,0 +1,10 @@
+/* From PR 19578. */
+extern void foo (void) __attribute__((noreturn));
+
+void
+g (void)
+{
+ void (*f) (void) = foo;
+ f ();
+ f ();
+}