Fix dangling references in thunks at -O0
When a thunk cannot be emitted in assembly directly, expand_thunk
generates regular GIMPLE code but unconditionally forces a tail
call to the target of the thunk. That's theoretically OK because
the thunk essentially forwards its parameters to the target, but
in practice the RTL expander can spill parameters passed by reference
on the stack in assign_parm_setup_reg.
gcc/ChangeLog:
* 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
load a parameter passed by reference if cfun->tail_call_marked.
gcc/testsuite/ChangeLog:
* gnat.dg/thunk1.adb: New test.
* gnat.dg/thunk1_pkg1.ads: New helper.
* gnat.dg/thunk1_pkg2.ads: Likewise.
* gnat.dg/thunk1_pkg2.adb: Likewise.