aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-tailcall.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2016-11-25 08:17:46 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2016-11-25 08:17:46 +0000
commit2c28c3e49983e8054850e60704edc391146e376d (patch)
tree58fb86ed3f74b01d70b68acd8de7a8c9713e941b /gcc/tree-tailcall.c
parent4ae35e698893dcf2b11ab6fa7b39a9f5e0973cd8 (diff)
downloadgcc-2c28c3e49983e8054850e60704edc391146e376d.zip
gcc-2c28c3e49983e8054850e60704edc391146e376d.tar.gz
gcc-2c28c3e49983e8054850e60704edc391146e376d.tar.bz2
Tighten check for whether sibcall references local variables
This loop: /* Make sure the tail invocation of this function does not refer to local variables. */ FOR_EACH_LOCAL_DECL (cfun, idx, var) { if (TREE_CODE (var) != PARM_DECL && auto_var_in_fn_p (var, cfun->decl) && (ref_maybe_used_by_stmt_p (call, var) || call_may_clobber_ref_p (call, var))) return; } triggered even for local variables that are passed by value. This meant that we didn't allow local aggregates to be passed to a sibling call but did (for example) allow global aggregates to be passed. I think the loop is really checking for indirect references, so should be able to skip any variables that never have their address taken. gcc/ * tree-tailcall.c (find_tail_calls): Allow calls to reference local variables if all references are known to be direct. gcc/testsuite/ * gcc.dg/tree-ssa/tailcall-8.c: New test. From-SVN: r242860
Diffstat (limited to 'gcc/tree-tailcall.c')
-rw-r--r--gcc/tree-tailcall.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/gcc/tree-tailcall.c b/gcc/tree-tailcall.c
index f97541d..66a0a4c 100644
--- a/gcc/tree-tailcall.c
+++ b/gcc/tree-tailcall.c
@@ -504,12 +504,14 @@ find_tail_calls (basic_block bb, struct tailcall **ret)
tail_recursion = true;
}
- /* Make sure the tail invocation of this function does not refer
- to local variables. */
+ /* Make sure the tail invocation of this function does not indirectly
+ refer to local variables. (Passing variables directly by value
+ is OK.) */
FOR_EACH_LOCAL_DECL (cfun, idx, var)
{
if (TREE_CODE (var) != PARM_DECL
&& auto_var_in_fn_p (var, cfun->decl)
+ && may_be_aliased (var)
&& (ref_maybe_used_by_stmt_p (call, var)
|| call_may_clobber_ref_p (call, var)))
return;