https://gcc.gnu.org/g:c938b91c2073c0d6db3f8b729b25360f8a54d4d1
commit r17-5777-gc938b91c2073c0d6db3f8b729b25360f8a54d4d1 Author: Eric Botcazou <[email protected]> Date: Sat Oct 31 17:15:19 2026 +0100 Ada: Fix adjustment of function result on secondary stack in allocator This is a regression present on the mainline and 16 branch, introduced by a recent optimization: when function calls return on the secondary stack, the result is effectively built as a temporary there and, therefore, needs to be later copied to the allocated memory, which requires a call to Adjust if the type is controlled. gcc/ada/ * exp_ch6.adb (Expand_Ctrl_Function_Call): Do not return early for the qualified expression of an allocator if the call returns on the secondary stack. Diff: --- gcc/ada/exp_ch6.adb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index ea6e239f2435..09cf9f395e37 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -5228,10 +5228,12 @@ package body Exp_Ch6 is -- The same optimization: if the returned value is used to initialize a -- dynamically allocated object, then no need to copy/readjust/finalize, - -- we can initialize it in place. + -- we can initialize it in place, provided that the call does not return + -- on the secondary stack. if Nkind (Par) = N_Qualified_Expression and then Nkind (Parent (Par)) = N_Allocator + and then not Use_Sec_Stack then return; end if;
