https://gcc.gnu.org/g:d6214b83e10d26bf116d4fca9de07a14cf4358cd
commit r13-9180-gd6214b83e10d26bf116d4fca9de07a14cf4358cd Author: Eric Botcazou <ebotca...@adacore.com> Date: Wed Oct 30 11:22:12 2024 +0100 ada: Fix spurious error on iterated component association with large index type This is only for the Ada 2022 form of the iterated component association. gcc/ada/ChangeLog: PR ada/117328 * exp_aggr.adb (Two_Pass_Aggregate_Expansion): Use a type sized from the index type to compute the length. Simplify and remove useless calls to New_Copy_Tree for this computation. Diff: --- gcc/ada/exp_aggr.adb | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index bb58613128b8..c7b57b9327ae 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -6481,6 +6481,9 @@ package body Exp_Aggr is Index_Id : constant Entity_Id := Make_Temporary (Loc, 'I', N); Index_Type : constant Entity_Id := Etype (First_Index (Etype (N))); Size_Id : constant Entity_Id := Make_Temporary (Loc, 'I', N); + Size_Type : constant Entity_Id := + Integer_Type_For + (Esize (Index_Type), Is_Unsigned_Type (Index_Type)); TmpE : constant Entity_Id := Make_Temporary (Loc, 'A', N); Assoc : Node_Id := First (Component_Associations (N)); @@ -6496,7 +6499,7 @@ package body Exp_Aggr is Size_Expr_Code := New_List ( Make_Object_Declaration (Loc, Defining_Identifier => Size_Id, - Object_Definition => New_Occurrence_Of (Standard_Integer, Loc), + Object_Definition => New_Occurrence_Of (Size_Type, Loc), Expression => Make_Integer_Literal (Loc, 0))); -- First pass: execute the iterators to count the number of elements @@ -6523,32 +6526,35 @@ package body Exp_Aggr is Insert_Actions (N, Size_Expr_Code); - -- Build a constrained subtype with the calculated length - -- and declare the proper bounded aggregate object. + -- Build a constrained subtype with the bounds deduced from + -- the size computed above and declare the aggregate object. -- The index type is some discrete type, so the bounds of the - -- constructed array are computed as T'Val (T'Pos (ineger bound)); + -- constrained subtype are computed as T'Val (integer bounds). declare + -- Pos_Lo := Index_Type'Pos (Index_Type'First) + Pos_Lo : constant Node_Id := Make_Attribute_Reference (Loc, - Prefix => New_Occurrence_Of (Index_Type, Loc), + Prefix => New_Occurrence_Of (Index_Type, Loc), Attribute_Name => Name_Pos, - Expressions => New_List ( + Expressions => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Index_Type, Loc), Attribute_Name => Name_First))); + -- Corresponding index value, i.e. Index_Type'First + Aggr_Lo : constant Node_Id := Make_Attribute_Reference (Loc, - Prefix => New_Occurrence_Of (Index_Type, Loc), - Attribute_Name => Name_Val, - Expressions => New_List (New_Copy_Tree (Pos_Lo))); + Prefix => New_Occurrence_Of (Index_Type, Loc), + Attribute_Name => Name_First); - -- Hi = Index_type'Pos (Lo + Size -1). + -- Pos_Hi := Pos_Lo + Size - 1 Pos_Hi : constant Node_Id := Make_Op_Add (Loc, - Left_Opnd => New_Copy_Tree (Pos_Lo), + Left_Opnd => Pos_Lo, Right_Opnd => Make_Op_Subtract (Loc, Left_Opnd => New_Occurrence_Of (Size_Id, Loc), @@ -6560,7 +6566,7 @@ package body Exp_Aggr is Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Index_Type, Loc), Attribute_Name => Name_Val, - Expressions => New_List (New_Copy_Tree (Pos_Hi))); + Expressions => New_List (Pos_Hi)); SubE : constant Entity_Id := Make_Temporary (Loc, 'T'); SubD : constant Node_Id := @@ -6583,6 +6589,7 @@ package body Exp_Aggr is Make_Object_Declaration (Loc, Defining_Identifier => TmpE, Object_Definition => New_Occurrence_Of (SubE, Loc)); + begin Insert_Actions (N, New_List (SubD, TmpD)); end;