> In fact I can probably reuse cfun->tail_call_marked for this purpose.
Like so.
* cgraphunit.c (cgraph_node::expand_thunk): Make sure to set
cfun->tail_call_marked when forcing a tail call.
* function.c (assign_parm_setup_reg): Always use a register to
retrieve a parameter passed by reference if cfun->tail_call_marked.
--
Eric Botcazou
diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 26d3995a0c0..bedb6e2eea1 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -2171,7 +2171,10 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)
}
}
else
- gimple_call_set_tail (call, true);
+ {
+ gimple_call_set_tail (call, true);
+ cfun->tail_call_marked = true;
+ }
/* Build return value. */
if (!DECL_BY_REFERENCE (resdecl))
@@ -2184,6 +2187,7 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)
else
{
gimple_call_set_tail (call, true);
+ cfun->tail_call_marked = true;
remove_edge (single_succ_edge (bb));
}
diff --git a/gcc/function.c b/gcc/function.c
index 2c8fa217f1f..314fd01c195 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -3322,13 +3322,15 @@ assign_parm_setup_reg (struct assign_parm_data_all *all, tree parm,
else
emit_move_insn (parmreg, validated_mem);
- /* If we were passed a pointer but the actual value can safely live
- in a register, retrieve it and use it directly. */
+ /* If we were passed a pointer but the actual value can live in a register,
+ retrieve it and use it directly. Note that we cannot use nominal_mode,
+ because it will have been set to Pmode above, we must use the actual mode
+ of the parameter instead. */
if (data->arg.pass_by_reference && TYPE_MODE (TREE_TYPE (parm)) != BLKmode)
{
- /* We can't use nominal_mode, because it will have been set to
- Pmode above. We must use the actual mode of the parm. */
- if (use_register_for_decl (parm))
+ /* Use a stack slot for debugging purposes, except if a tail call is
+ involved because this would create a dangling reference. */
+ if (use_register_for_decl (parm) || cfun->tail_call_marked)
{
parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
mark_user_reg (parmreg);