]> 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)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 9 Jun 2025 06:32:14 +0000 (08:32 +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 3a31a921fe31e032738711fd3e05d13d5b507524..c9b9e7f87ecaf35a73903db5d0d74c012bd257a5 100644 (file)
@@ -14129,6 +14129,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 9d93bf79c0ce9e8778cdbcd98361b4c8efe34da9..1263d7004d9fac8df0a452b666390b23b45a290a 100644 (file)
@@ -15099,7 +15099,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
@@ -15107,6 +15108,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