[Ada] Fix bogus error on conversion from Float to 128-bit unsigned
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 19 Aug 2020 19:54:21 +0000 (21:54 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 22 Oct 2020 12:11:23 +0000 (08:11 -0400)
gcc/ada/

* checks.adb (Apply_Float_Conversion_Check): Saturate the bounds
of the check to those of the base type of the expression.

gcc/ada/checks.adb

index 6d20fbbb2e554e82cbed37b013f20a55b574984e..355279507578f9d1be373f982d1dbbd75027cb5f 100644 (file)
@@ -2149,6 +2149,15 @@ package body Checks is
          Lo_OK := (Lo >= UR_From_Uint (Ifirst));
       end if;
 
+      --  Saturate the lower bound to that of the expression's type, because
+      --  we do not want to create an out-of-range value but we still need to
+      --  do a comparison to catch NaNs.
+
+      if Lo < Expr_Value_R (Type_Low_Bound (Expr_Type)) then
+         Lo := Expr_Value_R (Type_Low_Bound (Expr_Type));
+         Lo_OK := True;
+      end if;
+
       if Lo_OK then
 
          --  Lo_Chk := (X >= Lo)
@@ -2183,6 +2192,15 @@ package body Checks is
          Hi_OK := (Hi <= UR_From_Uint (Ilast));
       end if;
 
+      --  Saturate the higher bound to that of the expression's type, because
+      --  we do not want to create an out-of-range value but we still need to
+      --  do a comparison to catch NaNs.
+
+      if Hi > Expr_Value_R (Type_High_Bound (Expr_Type)) then
+         Hi := Expr_Value_R (Type_High_Bound (Expr_Type));
+         Hi_OK := True;
+      end if;
+
       if Hi_OK then
 
          --  Hi_Chk := (X <= Hi)