]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix inlining of fixed-lower-bound array for GNATprove
authorYannick Moy <moy@adacore.com>
Thu, 23 May 2024 12:39:19 +0000 (14:39 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 20 Jun 2024 08:50:56 +0000 (10:50 +0200)
Inlining in GNATprove may fail on a call to a subprogram with a formal
of an array type with fixed lower bound (a GNAT extension), because the
appropriate conversion is not used. Fix it.

Also fix the function that inserts an unchecked conversion, in cases where
it could skip sliding due to the target type having fixed lower bound.

gcc/ada/

* inline.adb (Establish_Actual_Mapping_For_Inlined_Call): In the
case of formal with a fixed lower bounds, insert appropriate
conversion like in the case of a constrained type.
* tbuild.adb (Unchecked_Convert_To): Do not skip the conversion
when it may involve sliding due to a type with fixed lower bound.

gcc/ada/inline.adb
gcc/ada/tbuild.adb

index f5c5426351595db9dcbeb003f2d4f1aa424a0b36..850145eb88732c51c487e26d068fa2466920b46f 100644 (file)
@@ -3165,7 +3165,9 @@ package body Inline is
 
          elsif Base_Type (Etype (F)) = Base_Type (Etype (A))
            and then Etype (F) /= Base_Type (Etype (F))
-           and then Is_Constrained (Etype (F))
+           and then (Is_Constrained (Etype (F))
+                      or else
+                     Is_Fixed_Lower_Bound_Array_Subtype (Etype (F)))
          then
             Temp_Typ := Etype (F);
 
@@ -3234,7 +3236,11 @@ package body Inline is
             --  GNATprove.
 
             elsif Etype (F) /= Etype (A)
-              and then (not GNATprove_Mode or else Is_Constrained (Etype (F)))
+              and then
+                (not GNATprove_Mode
+                   or else (Is_Constrained (Etype (F))
+                              or else
+                            Is_Fixed_Lower_Bound_Array_Subtype (Etype (F))))
             then
                New_A    := Unchecked_Convert_To (Etype (F), Relocate_Node (A));
                Temp_Typ := Etype (F);
index 51fa43c77ac82f2d3dc227432a7d21f047d5debf..b538911e8bc73b09b3ccd62c15d26925ab400a2b 100644 (file)
@@ -918,11 +918,17 @@ package body Tbuild is
       Result : Node_Id;
 
    begin
-      --  If the expression is already of the correct type, then nothing
-      --  to do, except for relocating the node
+      --  If the expression is already of the correct type, then nothing to do,
+      --  except for relocating the node. If Typ is an array type with fixed
+      --  lower bound, the expression might be of a subtype that does not
+      --  have this lower bound (on a slice), hence the conversion needs to
+      --  be preserved for sliding.
 
       if Present (Etype (Expr))
-        and then (Base_Type (Etype (Expr)) = Typ or else Etype (Expr) = Typ)
+        and then
+          ((Base_Type (Etype (Expr)) = Typ
+             and then not Is_Fixed_Lower_Bound_Array_Subtype (Typ))
+           or else Etype (Expr) = Typ)
       then
          return Relocate_Node (Expr);