]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Support fixed-lower-bound array types as generic actual parameters
authorGary Dismukes <dismukes@adacore.com>
Mon, 17 Mar 2025 18:30:00 +0000 (18:30 +0000)
committerEric Botcazou <ebotcazou@adacore.com>
Mon, 9 Jun 2025 08:24:22 +0000 (10:24 +0200)
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.

gcc/ada/sem_ch12.adb
gcc/ada/sem_ch3.adb

index 5768e28e90fcecaf2e9ec5cac66ca69807742c0a..d93788b779e9ac52d0744f069c7c05cb89b21486 100644 (file)
@@ -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
index 4b5c5b1a41eeaa69b73cf7c9c00db1d99656c0d7..9a25ff7b64051f9ddb2701b491eb211c7042d34f 100644 (file)
@@ -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