* [Ada] Fix problematic underflow for Float_Type'Value
@ 2022-05-18 8:43 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-05-18 8:43 UTC (permalink / raw)
To: gcc-patches; +Cc: Eric Botcazou
[-- Attachment #1: Type: text/plain, Size: 290 bytes --]
We need a couple of guards for boundary conditions in the support code.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* libgnat/s-dourea.adb ("/"): Add guard for zero and infinite
divisor.
* libgnat/s-valuer.adb (Scan_Raw_Real): Add guard for very large
exponent values.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1503 bytes --]
diff --git a/gcc/ada/libgnat/s-dourea.adb b/gcc/ada/libgnat/s-dourea.adb
--- a/gcc/ada/libgnat/s-dourea.adb
+++ b/gcc/ada/libgnat/s-dourea.adb
@@ -178,6 +178,12 @@ package body System.Double_Real is
P, R : Double_T;
begin
+ if Is_Infinity (B) or else Is_Zero (B) then
+ return (A.Hi / B, 0.0);
+ end if;
+ pragma Annotate (CodePeer, Intentional, "test always false",
+ "code deals with infinity");
+
Q1 := A.Hi / B;
-- Compute R = A - B * Q1
@@ -196,6 +202,12 @@ package body System.Double_Real is
R, S : Double_T;
begin
+ if Is_Infinity (B.Hi) or else Is_Zero (B.Hi) then
+ return (A.Hi / B.Hi, 0.0);
+ end if;
+ pragma Annotate (CodePeer, Intentional, "test always false",
+ "code deals with infinity");
+
Q1 := A.Hi / B.Hi;
R := A - B * Q1;
diff --git a/gcc/ada/libgnat/s-valuer.adb b/gcc/ada/libgnat/s-valuer.adb
--- a/gcc/ada/libgnat/s-valuer.adb
+++ b/gcc/ada/libgnat/s-valuer.adb
@@ -645,7 +645,14 @@ package body System.Value_R is
Ptr.all := Index;
Scan_Exponent (Str, Ptr, Max, Expon, Real => True);
- Scale := Scale + Expon;
+
+ -- Handle very large exponents like Scan_Exponent
+
+ if Expon < Integer'First / 10 or else Expon > Integer'Last / 10 then
+ Scale := Expon;
+ else
+ Scale := Scale + Expon;
+ end if;
-- Here is where we check for a bad based number
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-18 8:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-18 8:43 [Ada] Fix problematic underflow for Float_Type'Value Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).