]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Remove obsolete call to Establish_Transient_Scope
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 12 Nov 2025 15:13:03 +0000 (16:13 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 21 Nov 2025 08:29:37 +0000 (09:29 +0100)
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.

gcc/ada/exp_aggr.adb
gcc/ada/exp_ch7.adb

index 6b6b0aba4b03f6e3e9a01b07dd2d6a12f6313a9d..51fbdb8e1e9240c50ba5bbee74118ef0a93baa07 100644 (file)
@@ -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);
index 8c661900b06f529885be5825db6272413e17bef9..c170c23451d8ab29cd5cadf90324f32891357f99 100644 (file)
@@ -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.