diff --git a/gcc/tree-tailcall.c b/gcc/tree-tailcall.c index 2ecca4a..a9bbc97 100644 --- a/gcc/tree-tailcall.c +++ b/gcc/tree-tailcall.c @@ -375,6 +375,8 @@ find_tail_calls (basic_block bb, struct tailcall **ret) tree m, a; basic_block abb; size_t idx; + tree var; + referenced_var_iterator rvi; if (!single_succ_p (bb)) return; @@ -462,6 +464,16 @@ 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. */ + FOR_EACH_REFERENCED_VAR (var, rvi) + { + if (TREE_CODE (var) != PARM_DECL + && auto_var_in_fn_p (var, cfun->decl) + && ref_maybe_used_by_stmt_p (call, var)) + return; + } + /* Now check the statements after the call. None of them has virtual operands, so they may only depend on the call through its return value. The return value should also be dependent on each of them,