https://gcc.gnu.org/g:3ac5df1a7aaf9c986c367256cde09cf1d8f20c2b

commit r17-4762-g3ac5df1a7aaf9c986c367256cde09cf1d8f20c2b
Author: Eric Botcazou <[email protected]>
Date:   Tue Sep 29 12:06:05 2026 +0200

    Ada: Fix another fallout of recent changes to handling of static aggregates
    
    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).
    
    gcc/ada/
            * 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.

Diff:
---
 gcc/ada/exp_aggr.adb | 17 +++++++++++------
 gcc/ada/sem_aggr.adb |  1 -
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 80cd87f5d96e..3852b0633097 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 ba65c193845f..adab5d779f43 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

Reply via email to