https://gcc.gnu.org/g:56722ed86ead6226148f7fc73fbf5691be2e37b2

commit r16-5478-g56722ed86ead6226148f7fc73fbf5691be2e37b2
Author: Eric Botcazou <[email protected]>
Date:   Wed Nov 12 16:13:03 2025 +0100

    ada: Remove obsolete call to Establish_Transient_Scope
    
    There is a preceding call to Establish_Transient_Scope in the procedure for
    the cases where it is required, and we no longer build the aggregate on the
    stack before copying it to the heap for an allocator.
    
    gcc/ada/ChangeLog:
    
            * exp_aggr.adb (Expand_Array_Aggregate): Remove obsolete call to
            Establish_Transient_Scope for an allocator in a loop.
            * exp_ch7.adb (Establish_Transient_Scope): Adjust description.

Diff:
---
 gcc/ada/exp_aggr.adb | 13 +------------
 gcc/ada/exp_ch7.adb  |  5 +++--
 2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 6b6b0aba4b03..51fbdb8e1e92 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -6400,21 +6400,10 @@ package body Exp_Aggr is
              Object_Definition   => New_Occurrence_Of (Typ, Loc));
          Set_No_Initialization (Tmp_Decl, True);
 
-         --  If we are within a loop, the temporary will be pushed on the
-         --  stack at each iteration. If the aggregate is the expression
-         --  for an allocator, it will be immediately copied to the heap
-         --  and can be reclaimed at once. We create a transient scope
-         --  around the aggregate for this purpose.
-
-         if Ekind (Current_Scope) = E_Loop
-           and then Nkind (Parent_Node) = N_Allocator
-         then
-            Establish_Transient_Scope (N, Manage_Sec_Stack => False);
-
          --  If the parent is an assignment for which no controlled actions
          --  should take place, prevent the temporary from being finalized.
 
-         elsif Nkind (Parent_Node) = N_Assignment_Statement
+         if Nkind (Parent_Node) = N_Assignment_Statement
            and then No_Ctrl_Actions (Parent_Node)
          then
             Mutate_Ekind (Tmp, E_Variable);
diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index 8c661900b06f..c170c23451d8 100644
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -4276,8 +4276,9 @@ package body Exp_Ch7 is
    -- Establish_Transient_Scope --
    -------------------------------
 
-   --  This procedure is called each time a transient block has to be inserted
-   --  that is to say for each call to a function with unconstrained or tagged
+   --  This procedure is called when a transient scope has to be inserted in
+   --  the tree to manage the lifetime of temporaries created for a construct,
+   --  most notably for calls to functions with a controlled or unconstrained
    --  result. It creates a new scope on the scope stack in order to enclose
    --  all transient variables generated.

Reply via email to