public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Implementation of AI12-0212: iterator specs in array aggregates (II)
@ 2021-10-01  6:14 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-10-01  6:14 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ed Schonberg

[-- Attachment #1: Type: text/plain, Size: 512 bytes --]

This patch adds a guard to the code generated in the second pass of the
two-pass expansion for array aggregates described in AI12-0212.  The
guard is needed to prevent a spurious constraint error when incrementing
the index used for aggregate insertion, before exiting the loop.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* exp_aggr.adb (Expand_Array_Aggregate,
	Two_Pass_Aggregate_Expansion): Increment index for element
	insertion within the loop, only if upper bound has not been
	reached.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2005 bytes --]

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -6504,6 +6504,18 @@ package body Exp_Aggr is
                           Expressions =>
                             New_List (New_Occurrence_Of (Index_Id, Loc))));
 
+            --  Add guard to skip last increment when upper bound is reached.
+
+            Incr := Make_If_Statement (Loc,
+               Condition =>
+                  Make_Op_Ne (Loc,
+                  Left_Opnd  => New_Occurrence_Of (Index_Id, Loc),
+                  Right_Opnd =>
+                    Make_Attribute_Reference (Loc,
+                      Prefix => New_Occurrence_Of (Index_Type, Loc),
+                      Attribute_Name => Name_Last)),
+               Then_Statements => New_List (Incr));
+
             One_Loop := Make_Loop_Statement (Loc,
               Iteration_Scheme =>
                 Make_Iteration_Scheme (Loc,
@@ -6561,11 +6573,10 @@ package body Exp_Aggr is
          return;
 
       elsif Present (Component_Associations (N))
-         and then
-            Nkind (First (Component_Associations (N)))
-               = N_Iterated_Component_Association
-           and then Present
-             (Iterator_Specification (First (Component_Associations (N))))
+        and then Nkind (First (Component_Associations (N))) =
+                 N_Iterated_Component_Association
+        and then
+          Present (Iterator_Specification (First (Component_Associations (N))))
       then
          Two_Pass_Aggregate_Expansion (N);
          return;
@@ -7389,7 +7400,7 @@ package body Exp_Aggr is
          elsif Nkind (Comp) = N_Iterated_Element_Association then
             return -1;
 
-            --  TBD : Create code for a loop and add to generated code,
+            --  ??? Need to create code for a loop and add to generated code,
             --  as is done for array aggregates with iterated element
             --  associations, instead of using Append operations.
 



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

only message in thread, other threads:[~2021-10-01  6:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01  6:14 [Ada] Implementation of AI12-0212: iterator specs in array aggregates (II) 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).