]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Further fix non-stored discriminant in aggregate for GNATprove
authorpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 22 Jul 2019 13:57:18 +0000 (13:57 +0000)
committerpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 22 Jul 2019 13:57:18 +0000 (13:57 +0000)
GNATprove expects discriminants appearing in aggregates and their types
to be resolved to stored discriminants.  This extends the machinery that
makes sure this is the case for default initialization expressions so as
to also handle component associations in these expressions.

2019-07-22  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

* sem_aggr.adb (Rewrite_Bound): Be prepared for discriminals
too.
(Rewrite_Range;): Minor tweak.
(Resolve_Record_Aggregate): For a component with default
initialization whose expression is an array aggregate, also
rewrite the bounds of the component associations, if any.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@273679 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/sem_aggr.adb

index e9a4cbd9d052785d54f0c5223bd78bbe1140f9c9..202dfc7cacf10d724d9bd67e6a318d5d54f5e260 100644 (file)
@@ -1,3 +1,12 @@
+2019-07-22  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * sem_aggr.adb (Rewrite_Bound): Be prepared for discriminals
+       too.
+       (Rewrite_Range;): Minor tweak.
+       (Resolve_Record_Aggregate): For a component with default
+       initialization whose expression is an array aggregate, also
+       rewrite the bounds of the component associations, if any.
+
 2019-07-22  Gary Dismukes  <dismukes@adacore.com>
 
        * exp_ch5.adb (Expand_N_Case_Statement): In the case where a
index 2143cc4fcab415095dd7d3ace2b5e557d41cc557..7aacc5ff50bdea55ac6612a372c2ce8a4c250e5c 100644 (file)
@@ -4264,8 +4264,15 @@ package body Sem_Aggr is
             Expr_Disc : Node_Id)
          is
          begin
-            if Nkind (Bound) = N_Identifier
-              and then Entity (Bound) = Disc
+            if Nkind (Bound) /= N_Identifier then
+               return;
+            end if;
+
+            --  We expect either the discriminant or the discriminal
+
+            if Entity (Bound) = Disc
+              or else (Ekind (Entity (Bound)) = E_In_Parameter
+                        and then Discriminal_Link (Entity (Bound)) = Disc)
             then
                Rewrite (Bound, New_Copy_Tree (Expr_Disc));
             end if;
@@ -4280,9 +4287,7 @@ package body Sem_Aggr is
       --  Start of processing for Rewrite_Range
 
       begin
-         if Has_Discriminants (Root_Type)
-           and then Nkind (Rge) = N_Range
-         then
+         if Has_Discriminants (Root_Type) and then Nkind (Rge) = N_Range then
             Low := Low_Bound (Rge);
             High := High_Bound (Rge);
 
@@ -4903,7 +4908,9 @@ package body Sem_Aggr is
                         --  Root record type whose discriminants may be used as
                         --  bounds in range nodes.
 
-                        Index : Node_Id;
+                        Assoc  : Node_Id;
+                        Choice : Node_Id;
+                        Index  : Node_Id;
 
                      begin
                         --  Rewrite the range nodes occurring in the indexes
@@ -4919,12 +4926,26 @@ package body Sem_Aggr is
                         end loop;
 
                         --  Rewrite the range nodes occurring as aggregate
-                        --  bounds.
+                        --  bounds and component associations.
 
-                        if Nkind (Expr) = N_Aggregate
-                          and then Present (Aggregate_Bounds (Expr))
-                        then
-                           Rewrite_Range (Rec_Typ, Aggregate_Bounds (Expr));
+                        if Nkind (Expr) = N_Aggregate then
+                           if Present (Aggregate_Bounds (Expr)) then
+                              Rewrite_Range (Rec_Typ, Aggregate_Bounds (Expr));
+                           end if;
+
+                           if Present (Component_Associations (Expr)) then
+                              Assoc := First (Component_Associations (Expr));
+                              while Present (Assoc) loop
+                                 Choice := First (Choices (Assoc));
+                                 while Present (Choice) loop
+                                    Rewrite_Range (Rec_Typ, Choice);
+
+                                    Next (Choice);
+                                 end loop;
+
+                                 Next (Assoc);
+                              end loop;
+                           end if;
                         end if;
                      end;
                   end if;