From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id BB2E73857815; Wed, 18 May 2022 08:43:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB2E73857815 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-595] [Ada] Fix problematic underflow for Float_Type'Value X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/master X-Git-Oldrev: ba89624e938a9309a0a8a672b2753159cf0a8a78 X-Git-Newrev: 7c77ec1199c3a3d1ac48c9d963b8389c10a2a5bf Message-Id: <20220518084347.BB2E73857815@sourceware.org> Date: Wed, 18 May 2022 08:43:47 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 May 2022 08:43:47 -0000 https://gcc.gnu.org/g:7c77ec1199c3a3d1ac48c9d963b8389c10a2a5bf commit r13-595-g7c77ec1199c3a3d1ac48c9d963b8389c10a2a5bf Author: Eric Botcazou 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