This is a regression present on the mainline and 16 branch, introduced by a 
recent optimization: when a function call returns 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.

Tested on x86-64/Linux, applied on the mainline and 16 branch.


2026-10-31  Eric Botcazou  <[email protected]>

        * 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.

-- 
Eric Botcazou
diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index ea6e239f243..09cf9f395e3 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;

Reply via email to