The problem is that the Compile_Time_Known_Aggregate flag is set on an array
aggregate whose elements are all static but whose subtype has a dynamic size
because its component subtype has one too. Such an array aggregate cannot
be passed directly to the back end, and building a static actual component
subtype looks fairly complicated in the general case, so this prevents the
Compile_Time_Known_Aggregate flag from being set in this case (both for
array and record aggregates for the sake of consistency).
Tested on x86-64/Linux, applied on the mainline.
2026-09-29 Eric Botcazou <[email protected]>
* exp_aggr.adb (Convert_To_Positional): Adjust commentary. Do not
set Compile_Time_Known_Aggregate on the aggregate if the size of its
type is not known at compile time.
(Expand_Record_Aggregate.Build_Back_End_Aggregate): Likewise.
* sem_aggr.adb (Array_Aggr_Subtype): Set Size_Known_At_Compile_Time
on the subtype even if the aggregate does not come from source.
--
Eric Botcazoudiff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 80cd87f5d96..3852b063309 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -4439,7 +4439,10 @@ package body Exp_Aggr is
Max_Others_Replicate : constant Nat := Max_Aggregate_Size (N);
Ctyp : constant Entity_Id := Component_Type (Typ);
- Static_Components : Boolean := True;
+ Static_Components : Boolean := True;
+ -- Flag to indicate whether all components are compile-time known,
+ -- and the aggregate can be constructed statically and handled by
+ -- the back-end. Set to False by Check_Static_Components.
procedure Check_Static_Components;
-- Check whether all components of the aggregate are compile-time known
@@ -4975,22 +4978,24 @@ package body Exp_Aggr is
return;
end if;
+ -- Check whether the components are static
+
Check_Static_Components;
-- If the size is known, or all the components are static, try to
-- build a fully positional aggregate.
-- The size of the type may not be known for an aggregate with
- -- discriminated array components, but if the components are static
+ -- discriminated components, but if the components are static
-- it is still possible to verify statically that the length is
- -- compatible with the upper bound of the type, and therefore it is
- -- worth flattening such aggregates as well.
+ -- compatible with the upper bound of the type, and therefore it
+ -- is worth flattening such aggregates as well.
if Aggr_Size_OK (N)
and then
Flatten (N, Dims, First_Index (Typ), First_Index (Base_Type (Typ)))
then
- if Static_Components then
+ if Static_Components and then Size_Known_At_Compile_Time (Typ) then
Set_Compile_Time_Known_Aggregate (N);
Set_Expansion_Delayed (N, False);
end if;
@@ -8152,7 +8157,7 @@ package body Exp_Aggr is
-- If the aggregate is static and can be handled by the back-end,
-- nothing left to do.
- if Static_Components then
+ if Static_Components and then Size_Known_At_Compile_Time (Typ) then
Set_Compile_Time_Known_Aggregate (N);
Set_Expansion_Delayed (N, False);
end if;
diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index ba65c193845..adab5d779f4 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -776,7 +776,6 @@ package body Sem_Aggr is
Set_Size_Known_At_Compile_Time
(Itype,
Is_Fully_Positional
- and then Comes_From_Source (N)
and then Size_Known_At_Compile_Time (Component_Type (Typ)));
-- We always need a freeze node for a packed array subtype, so that we