[Ada] Fix expansion of delta aggregates with slices

Message ID 20200707092736.GA41482@adacore.com
State New
Headers show
  • [Ada] Fix expansion of delta aggregates with slices
Related show

Commit Message

Pierre-Marie de Rodat July 7, 2020, 9:27 a.m.
When creating an anonymous object of the delta aggregate, use the type
of the base expression, not the type of the delta aggregate itself. This
follows from Ada 2020 4.3.4(14/5):

  "The bounds of the anonymous object of an array_delta_aggregate and the
   discriminants and tag (if any) of the anonymous object of a
   record_delta_aggregate are those of the base_expression."

Ideally both types should be the same, but the type of the
N_Delta_Aggregate (which is set in Resolve_Delta_Aggregate) is the type
expected by the context and it might have different bounds,
discriminants or tags (while still being compatible wrt assignments). In
particular, then the bounds are different, they must come from the base
expression, because the choices of the array_component_association_list
refer to this base expression, not to the bounds expected by the

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


	* exp_aggr.adb (Expand_N_Delta_Aggregate): Use type of the delta
	base expression for the anonymous object of the delta aggregate.


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
@@ -6845,7 +6845,7 @@  package body Exp_Aggr is
    procedure Expand_N_Delta_Aggregate (N : Node_Id) is
       Loc  : constant Source_Ptr := Sloc (N);
-      Typ  : constant Entity_Id  := Etype (N);
+      Typ  : constant Entity_Id  := Etype (Expression (N));
       Decl : Node_Id;