public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-406] [Ada] Fix iterated component association for array aggregate
@ 2022-05-13  8:09 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-05-13  8:09 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e3584606f5cb9bfc717a19e96731bc35ea11a40e

commit r13-406-ge3584606f5cb9bfc717a19e96731bc35ea11a40e
Author: Marc Poulhiès <poulhies@adacore.com>
Date:   Fri Feb 18 16:35:06 2022 +0100

    [Ada] Fix iterated component association for array aggregate
    
    Create a scope for the Ada 2022 iterated component association loops. In
    the case of elements needing finalization, the late expansion would
    crash on references to the loop variable within the loop body.
    
    gcc/ada/
    
            * exp_aggr.adb (Gen_Loop): Create scope for loop variable of
            iterated components.

Diff:
---
 gcc/ada/exp_aggr.adb | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 939d091e065..72f65555681 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -1916,6 +1916,8 @@ package body Exp_Aggr is
          Is_Iterated_Component : constant Boolean :=
            Parent_Kind (Expr) = N_Iterated_Component_Association;
 
+         Ent : Entity_Id;
+
          L_J : Node_Id;
 
          L_L : Node_Id;
@@ -2025,10 +2027,28 @@ package body Exp_Aggr is
          --  Otherwise construct the loop, starting with the loop index L_J
 
          if Is_Iterated_Component then
+
+            --  Create a new scope for the loop variable so that the
+            --  following Gen_Assign (that ends up calling
+            --  Preanalyze_And_Resolve) can correctly find it.
+
+            Ent := New_Internal_Entity (E_Loop,
+                 Current_Scope, Loc, 'L');
+            Set_Etype  (Ent, Standard_Void_Type);
+            Set_Parent (Ent, Parent (Parent (Expr)));
+            Push_Scope (Ent);
+
             L_J :=
               Make_Defining_Identifier (Loc,
                 Chars => (Chars (Defining_Identifier (Parent (Expr)))));
 
+            Enter_Name (L_J);
+
+            --  The Etype will be set by a later Analyze call.
+            Set_Etype (L_J, Any_Type);
+
+            Mutate_Ekind (L_J, E_Variable);
+            Set_Scope (L_J, Ent);
          else
             L_J := Make_Temporary (Loc, 'J', L);
          end if;
@@ -2083,6 +2103,10 @@ package body Exp_Aggr is
               Iteration_Scheme => L_Iteration_Scheme,
               Statements       => L_Body));
 
+         if Is_Iterated_Component then
+            End_Scope;
+         end if;
+
          --  A small optimization: if the aggregate is initialized with a box
          --  and the component type has no initialization procedure, remove the
          --  useless empty loop.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-13  8:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13  8:09 [gcc r13-406] [Ada] Fix iterated component association for array aggregate Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).