]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Add assertions to Uintp (UI_Is_In_Int_Range)
authorBob Duff <duff@adacore.com>
Tue, 6 Jul 2021 21:12:32 +0000 (17:12 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 21 Sep 2021 15:25:00 +0000 (15:25 +0000)
gcc/ada/

* uintp.ads, uintp.adb (UI_Is_In_Int_Range): Change the type of
the formal parameter to Valid_Uint. Remove code that preserved
the previous behavior, and replace it with an assertion. The
previous behavior is no longer needed given the recent change to
gigi.
(No, Present): Add comment.

gcc/ada/uintp.adb
gcc/ada/uintp.ads

index dad4e9bcf8949a7e0a8d7053052a1dd80a93342c..29d409b49e1139e24dc21f56c9497d3b0ab64e1e 100644 (file)
@@ -1693,16 +1693,15 @@ package body Uintp is
    -- UI_Is_In_Int_Range --
    -------------------------
 
-   function UI_Is_In_Int_Range (Input : Uint) return Boolean is
+   function UI_Is_In_Int_Range (Input : Valid_Uint) return Boolean is
+      pragma Assert (Present (Input));
+      --  Assertion is here in case we're called from C++ code, which does
+      --  not check the predicates.
    begin
       --  Make sure we don't get called before Initialize
 
       pragma Assert (Uint_Int_First /= Uint_0);
 
-      if No (Input) then -- Preserve old behavior
-         return True;
-      end if;
-
       if Direct (Input) then
          return True;
       else
index 75bc5581fb50af01bd03d410a1ffd987b38e04a1..d9f1f8f70fbb81893f1e1413199e6eb459dbbe31 100644 (file)
@@ -90,6 +90,10 @@ package Uintp is
    Uint_Minus_127 : constant Uint;
    Uint_Minus_128 : constant Uint;
 
+   --  Functions for detecting No_Uint. Note that clients of this package
+   --  cannot use "=" and "/=" to compare with No_Uint; they must use No
+   --  and Present instead.
+
    function No (X : Uint) return Boolean is (X = No_Uint);
    --  Note that this is using the predefined "=", not the "=" declared below,
    --  which would blow up on No_Uint.
@@ -169,10 +173,9 @@ package Uintp is
    pragma Inline (UI_Gt);
    --  Compares integer values for greater than
 
-   function UI_Is_In_Int_Range (Input : Uint) return Boolean;
+   function UI_Is_In_Int_Range (Input : Valid_Uint) return Boolean;
    pragma Inline (UI_Is_In_Int_Range);
    --  Determines if universal integer is in Int range.
-   --  Input should probably be of type Valid_Uint.
 
    function UI_Le (Left : Valid_Uint; Right : Valid_Uint) return Boolean;
    function UI_Le (Left : Int;  Right : Valid_Uint) return Boolean;