https://gcc.gnu.org/g:d96603a48d338a92b78628016d00cbf11576621e
commit r15-9806-gd96603a48d338a92b78628016d00cbf11576621e Author: Gary Dismukes <dismu...@adacore.com> Date: Mon Mar 17 18:30:00 2025 +0000 ada: Support fixed-lower-bound array types as generic actual parameters Attempting to use a fixed-lower-bound array type (or subtype) as an actual parameter for a formal unconstrained array type was being rejected by the compiler (complaining about the index type of the actual not matching the index type of the formal type). The compiler was improperly testing the actual's FLB range and finding that it didn't statically match the index type of the formal array type; it should instead test the underlying index type of the FLB type or subtype. gcc/ada/ChangeLog: * sem_ch3.adb (Constrain_Index): In the case of a fixed-lower-bound index, set Etype of the newly created itype's Scalar_Range from the index's Etype. * sem_ch12.adb (Validate_Array_Type_Instance): If the actual subtype is a fixed-lower-bound type, then check again the Etype of its Scalar_Range. Diff: --- gcc/ada/sem_ch12.adb | 10 ++++++++++ gcc/ada/sem_ch3.adb | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index 5768e28e90fc..d93788b779e9 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -14132,6 +14132,16 @@ package body Sem_Ch12 is T2 := Etype (I2); end if; + -- In the case of a fixed-lower-bound subtype, we want to check + -- against the index type's range rather than the range of the + -- subtype (which will be seen as unconstrained, and whose bounds + -- won't generally match those of the formal unconstrained array + -- type's corresponding index type). + + if Is_Fixed_Lower_Bound_Index_Subtype (T2) then + T2 := Etype (Scalar_Range (T2)); + end if; + if not Subtypes_Match (Find_Actual_Type (Etype (I1), A_Gen_T), T2) then diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 4b5c5b1a41ee..9a25ff7b6405 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -15092,7 +15092,8 @@ package body Sem_Ch3 is -- If this is a range for a fixed-lower-bound subtype, then set the -- index itype's low bound to the FLB and the index itype's upper bound -- to the high bound of the parent array type's index subtype. Also, - -- mark the itype as an FLB index subtype. + -- set the Etype of the new scalar range and mark the itype as an FLB + -- index subtype. if Nkind (S) = N_Range and then Is_FLB_Index then Set_Scalar_Range @@ -15100,6 +15101,7 @@ package body Sem_Ch3 is Make_Range (Sloc (S), Low_Bound => Low_Bound (S), High_Bound => Type_High_Bound (T))); + Set_Etype (Scalar_Range (Def_Id), Etype (Index)); Set_Is_Fixed_Lower_Bound_Index_Subtype (Def_Id); else