]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix handling of iterated component associations with sub-aggregates
authorPiotr Trojanek <trojanek@adacore.com>
Tue, 16 Jul 2024 14:07:59 +0000 (16:07 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 2 Aug 2024 07:08:10 +0000 (09:08 +0200)
Fix a number of problems in handling of actions generated for a
2-dimensional array aggregate where the outer aggregate has iterated
component association and the inner aggregate involves run-time checks.

gcc/ada/

* exp_aggr.adb (Add_Loop_Actions): Actions are now attached to
iterated component association just like they are attached to
ordinary component association.
(Build_Array_Aggr_Code): If resolution of the array aggregate
generated some actions, e.g. for run-time checks, then we must
keep them; same for the Other_Clause.
* sem_aggr.adb (Resolve_Iterated_Component_Association): Unset
references to iterator variable in loop actions (which might come
from run-time check), just these references are unset in the
expression itself.

gcc/ada/exp_aggr.adb
gcc/ada/sem_aggr.adb

index 8496fcd9b0029b76dbb932795d2964dfbd6e30fb..aa6079d82b58b948c68ed6cea3fb5467ad955c66 100644 (file)
@@ -1259,7 +1259,8 @@ package body Exp_Aggr is
             if No (Expr) then
                return Lis;
 
-            elsif Nkind (Parent (Expr)) = N_Component_Association
+            elsif Nkind (Parent (Expr)) in N_Component_Association
+                                         | N_Iterated_Component_Association
               and then Present (Loop_Actions (Parent (Expr)))
             then
                Res := Loop_Actions (Parent (Expr));
@@ -1962,7 +1963,9 @@ package body Exp_Aggr is
 
                Bounds := Get_Index_Bounds (Choice);
 
-               if Low /= High then
+               if Low /= High
+                 and then No (Loop_Actions (Assoc))
+               then
                   Set_Loop_Actions (Assoc, New_List);
                end if;
 
@@ -2038,7 +2041,12 @@ package body Exp_Aggr is
 
                   if First or else not Empty_Range (Low, High) then
                      First := False;
-                     Set_Loop_Actions (Others_Assoc, New_List);
+                     if Present (Loop_Actions (Others_Assoc)) then
+                        pragma Assert
+                          (Is_Empty_List (Loop_Actions (Others_Assoc)));
+                     else
+                        Set_Loop_Actions (Others_Assoc, New_List);
+                     end if;
                      Expr := Get_Assoc_Expr (Others_Assoc);
                      Append_List (Gen_Loop (Low, High, Expr), To => New_Code);
                   end if;
index 656d789de735945df827c3c508470c361f745db5..087e324b5c154f041c8aba378f9931b2c622fc66 100644 (file)
@@ -2212,6 +2212,15 @@ package body Sem_Aggr is
 
          if Operating_Mode /= Check_Semantics then
             Remove_References (Expr);
+            declare
+               Loop_Action : Node_Id;
+            begin
+               Loop_Action := First (Loop_Actions (N));
+               while Present (Loop_Action) loop
+                  Remove_References (Loop_Action);
+                  Next (Loop_Action);
+               end loop;
+            end;
          end if;
 
          --  An iterated_component_association may appear in a nested