From patchwork Wed May 18 08:43:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 54132 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 520FD3857407 for ; Wed, 18 May 2022 08:54:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 520FD3857407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652864088; bh=ncnEcgUr5U+rUf8tufI5i0+DHdSwBhVEpHjY9nQoJRM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=pp54rUz0txuZO8mVIx3uzfOKoNzlpt5oKq2di6ZdT4Fu9WPeA9LGU2RHz6fN8Y7lE OWrYScwGY2T23s8C890H9O4zOpm+fOg2l1IDvpW764LS6U6B9g2uZvxJsK1TWMaUJx 8ZS7M/fGWnZNEL+vmzC8JJU+fH6LSzxSIdGBthRw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id C845F3858C53 for ; Wed, 18 May 2022 08:43:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C845F3858C53 Received: by mail-wr1-x42b.google.com with SMTP id w4so1611798wrg.12 for ; Wed, 18 May 2022 01:43:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=ncnEcgUr5U+rUf8tufI5i0+DHdSwBhVEpHjY9nQoJRM=; b=x58jSpjZt9BqC9CBNSCRbF5Ys8fYQzeiPql5iA2aUsLi1CfCScm5s+j+VDT1lAABEN SQnAO4K2xdHQfGonaiGFQ9DXc6nS6/7PkclepWh+IH2Dq07mjzpAl89AoqVYmmGW2wpM VNdpgfdGrEeESDCtRHZ6OVrHCxxwjrblRtevjp+l2xUJ3Lsj7t+h8H5F+wzA203t8K44 UPQ47QqM1O/CbvxF5lzdCBI7y6bQdGsH1KGnJzBSIK3B1bNSd/8aHzvZR79p44BZQ8OV dbXGOEoZuwcIWljXP9/1Weg9wRamadyewiho08b8kaW0iQrSr8ToNtm3ln9vJGqsCRBK IYBA== X-Gm-Message-State: AOAM532t8FNNdBX79UchS6hgjnoU7lMoGMoweQLQH4cQpuBD9/ZWtj3C rx5LpU/FVcPTByt8A1IzNNwBA0Rj1VXHXg== X-Google-Smtp-Source: ABdhPJyyoHwknvnaLN9/rZqJn1EDN4mYacL8iijhCL9QVpTxIH4VCtc47ybPkb10vks0dYTsfrYF0Q== X-Received: by 2002:a5d:64ac:0:b0:20c:62a1:b4c9 with SMTP id m12-20020a5d64ac000000b0020c62a1b4c9mr21609811wrp.491.1652863393669; Wed, 18 May 2022 01:43:13 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id b11-20020a5d45cb000000b0020c5253d8e1sm1573595wrs.45.2022.05.18.01.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 01:43:13 -0700 (PDT) Date: Wed, 18 May 2022 08:43:12 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix problematic underflow for Float_Type'Value Message-ID: <20220518084312.GA3326542@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Eric Botcazou Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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. 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