When resolving record aggregates, frontend was creating "others => <>"
association to represent nested components, for example:
type T1 (D1 : Boolean := False) is record
C1 : Boolean := True;
end record;
type T2 is record
C2 : T1;
end record;
X2 : T2 := (others => <>);
was expanded into:
x2 : t2 := (c2 => (d1 => false, others => <>));
^^^^^^^^^^^^
Now those components are represented explicitly:
x2 : t2 := (c2 => (d1 => false, c1 => <>));
^^^^^^^^
This makes no difference for the compiler (except that heavily nested
records aggregates will be resolved into bigger AST), but GNATprove will
not need to rediscover which components are covered by the "others =>
<>" association.
Tested on x86_64-pc-linux-gnu, committed on trunk
2020-06-11 Piotr Trojanek <troja...@adacore.com>
gcc/ada/
* sem_aggr.adb (Add_Association): Add assertion about the formal
parameters.
(Propagate_Discriminants): Always add an explicit component
association, so that an "others => <>" association is never
needed.
--- gcc/ada/sem_aggr.adb
+++ gcc/ada/sem_aggr.adb
@@ -3393,6 +3393,8 @@ package body Sem_Aggr is
-- If this is a box association the expression is missing, so use the
-- Sloc of the aggregate itself for the new association.
+ pragma Assert (Present (Expr) xor Is_Box_Present);
+
if Present (Expr) then
Loc := Sloc (Expr);
else
@@ -3804,8 +3806,6 @@ package body Sem_Aggr is
is
Loc : constant Source_Ptr := Sloc (N);
- Needs_Box : Boolean := False;
-
procedure Process_Component (Comp : Entity_Id);
-- Add one component with a box association to the inner aggregate,
-- and recurse if component is itself composite.
@@ -3834,7 +3834,9 @@ package body Sem_Aggr is
Build_Constrained_Itype
(New_Aggr, T, Component_Associations (New_Aggr));
else
- Needs_Box := True;
+ Add_Association
+ (Comp, Empty, Component_Associations (Aggr),
+ Is_Box_Present => True);
end if;
end Process_Component;
@@ -3885,14 +3887,6 @@ package body Sem_Aggr is
Next_Component (Comp);
end loop;
end if;
-
- if Needs_Box then
- Append_To (Component_Associations (Aggr),
- Make_Component_Association (Loc,
- Choices => New_List (Make_Others_Choice (Loc)),
- Expression => Empty,
- Box_Present => True));
- end if;
end Propagate_Discriminants;
-----------------------