]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix resolving tagged operations in array aggregates
authorViljar Indus <indus@adacore.com>
Fri, 9 Feb 2024 10:29:41 +0000 (12:29 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 16 May 2024 08:49:29 +0000 (10:49 +0200)
In the Two_Pass_Aggregate_Expansion we were removing
all of the entity links in the Iterator_Specification
to avoid reusing the same Iterator_Definition in both
loops.

However this approach was also breaking the links to
calls with dot notation that had been transformed to
the regular call notation.

In order to circumvent this, explicitly create new
identifier definitions when copying the
Iterator_Specfications for both of the loops.

gcc/ada/

* exp_aggr.adb (Two_Pass_Aggregate_Expansion):
Explicitly create new Defining_Iterators for both
of the loops.

gcc/ada/exp_aggr.adb

index bdaca4aab58b86fb1a1afeaf9cbafd3d32048a13..f04dba719d9250b27b0247edeed5b11dea19c79a 100644 (file)
@@ -5714,6 +5714,7 @@ package body Exp_Aggr is
          Iter     : Node_Id;
          New_Comp : Node_Id;
          One_Loop : Node_Id;
+         Iter_Id  : Entity_Id;
 
          Size_Expr_Code : List_Id;
          Insertion_Code : List_Id := New_List;
@@ -5730,6 +5731,7 @@ package body Exp_Aggr is
 
          while Present (Assoc) loop
             Iter := Iterator_Specification (Assoc);
+            Iter_Id := Defining_Identifier (Iter);
             Incr := Make_Assignment_Statement (Loc,
                       Name => New_Occurrence_Of (Size_Id, Loc),
                       Expression =>
@@ -5737,10 +5739,16 @@ package body Exp_Aggr is
                          Left_Opnd  => New_Occurrence_Of (Size_Id, Loc),
                          Right_Opnd => Make_Integer_Literal (Loc, 1)));
 
+            --  Avoid using the same iterator definition in both loops by
+            --  creating a new iterator for each loop and mapping it over the
+            --  original iterator references.
+
             One_Loop := Make_Implicit_Loop_Statement (N,
               Iteration_Scheme =>
                 Make_Iteration_Scheme (Loc,
-                  Iterator_Specification => New_Copy_Tree (Iter)),
+                  Iterator_Specification =>
+                     New_Copy_Tree (Iter,
+                        Map => New_Elmt_List (Iter_Id, New_Copy (Iter_Id)))),
                 Statements => New_List (Incr));
 
             Append (One_Loop, Size_Expr_Code);
@@ -5837,6 +5845,7 @@ package body Exp_Aggr is
 
          while Present (Assoc) loop
             Iter := Iterator_Specification (Assoc);
+            Iter_Id := Defining_Identifier (Iter);
             New_Comp := Make_Assignment_Statement (Loc,
                Name =>
                  Make_Indexed_Component (Loc,
@@ -5869,10 +5878,16 @@ package body Exp_Aggr is
                       Attribute_Name => Name_Last)),
                Then_Statements => New_List (Incr));
 
+            --  Avoid using the same iterator definition in both loops by
+            --  creating a new iterator for each loop and mapping it over the
+            --  original iterator references.
+
             One_Loop := Make_Implicit_Loop_Statement (N,
               Iteration_Scheme =>
                 Make_Iteration_Scheme (Loc,
-                  Iterator_Specification => Copy_Separate_Tree (Iter)),
+                  Iterator_Specification =>
+                     New_Copy_Tree (Iter,
+                        Map => New_Elmt_List (Iter_Id, New_Copy (Iter_Id)))),
                 Statements => New_List (New_Comp, Incr));
 
             Append (One_Loop, Insertion_Code);