public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-595] [Ada] Fix problematic underflow for Float_Type'Value
Date: Wed, 18 May 2022 08:43:47 +0000 (GMT)	[thread overview]
Message-ID: <20220518084347.BB2E73857815@sourceware.org> (raw)

https://gcc.gnu.org/g:7c77ec1199c3a3d1ac48c9d963b8389c10a2a5bf

commit r13-595-g7c77ec1199c3a3d1ac48c9d963b8389c10a2a5bf
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Mon Apr 4 23:16:53 2022 +0200

    [Ada] Fix problematic underflow for Float_Type'Value
    
    We need a couple of guards for boundary conditions in the support code.
    
    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.

Diff:
---
 gcc/ada/libgnat/s-dourea.adb | 12 ++++++++++++
 gcc/ada/libgnat/s-valuer.adb |  9 ++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/libgnat/s-dourea.adb b/gcc/ada/libgnat/s-dourea.adb
index a6cf2a1ca0b..4f378d6cb6d 100644
--- 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
index 4b4e8873c3e..b474f8429e5 100644
--- 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


                 reply	other threads:[~2022-05-18  8:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220518084347.BB2E73857815@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).