From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 117884 invoked by alias); 10 Sep 2019 18:46:53 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 117876 invoked by uid 89); 10 Sep 2019 18:46:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-31.9 required=5.0 tests=AWL,BAYES_00,ENV_AND_HDR_SPF_MATCH,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS,USER_IN_DEF_SPF_WL autolearn=ham version=3.3.1 spammy= X-HELO: mail-wm1-f67.google.com Received: from mail-wm1-f67.google.com (HELO mail-wm1-f67.google.com) (209.85.128.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Sep 2019 18:46:51 +0000 Received: by mail-wm1-f67.google.com with SMTP id p7so687971wmp.4 for ; Tue, 10 Sep 2019 11:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GrFlhmSOjLUPDW4QnjHy5Qfw/Rc2//tyz45jR0XV1s0=; b=fPEZmzy9pgJul5GQBOAtKcipByQj73Td41PF6X+lh7rcmEpyiUKnDEhcQp2TO5gv4K w4VLthSmV6/eFC7yPVYS4UW6XNawDDMqVbWayJ4AdEYm5et6Mr4d2PkOxAjUJBAG0x3v voOHemz8kEkRZ4SyARv/OluQRd0OipZBTCVAsPKFEPRVYoDf9VCvcPw/QPsyUVFEWbbx PtH0/N5qD3U8KL+dhTjBI90rNjgzEBl2K2bsKyT1wfzbvsZnvw3LGIe3FJZo4Glg0HHE JDkmtmott61lhqBHzcUGN8mn9b4l4BQxMmP0Z+sZ63iDGVn+Cw8e75Ey3H53NXuValeh +RSQ== MIME-Version: 1.0 References: <20190828032808.242363-1-tamur@google.com> <20190828082935.GQ6076@embecosm.com> In-Reply-To: From: "Ali Tamur via gdb-patches" Reply-To: Ali Tamur Date: Tue, 10 Sep 2019 18:46:00 -0000 Message-ID: Subject: Re: [PATCH] Fix float to LONGEST conversion. To: Andrew Burgess Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg00166.txt.bz2 Hi, If there are no other concerns I am going to submit this tomorrow morning. Thanks. On Sun, Sep 8, 2019 at 7:36 PM Ali Tamur wrote: > > Hi, > Can I submit if there aren't any other concerns? > Thanks, > Ali > > On Wed, Sep 4, 2019 at 2:28 PM Ali Tamur wrote: > > > > Updated the commit message: > > > > > Fix float to LONGEST conversion. > > > > The code used to have undefined behaviour when template parameter is float and > > host_float is NaN, because it attempted to convert NaN value to LONGEST at the > > last statement. This frequently caused crashes on tests that checked "info > > all-registers" (at least when the code is compiled with clang; I didn't test > > with gdb). > > > > On Wed, Aug 28, 2019 at 1:29 AM Andrew Burgess wrote: > >> > >> * Ali Tamur via gdb-patches [2019-08-27 20:28:08 -0700]: > >> > >> > The code used to have undefined behaviour. > >> > >> I would much prefer to see a more detailed explanation for _why_ the > >> previous behaviour is undefined. I ran my eye over the old code but > >> didn't see anything obvious. > >> > >> If at a later date I come back and want to figure out why this patch > >> went in it would be nice if the commit message could tell me > >> everything I need to know. > >> > >> Thanks, > >> Andrew > >> > >> > >> > >> > > >> > > >> > gdb/ChangeLog: > >> > *gdb/target-float.c (host_float_ops::to_longest): Update > >> > implementation. > >> > --- > >> > gdb/target-float.c | 17 +++++++++++------ > >> > 1 file changed, 11 insertions(+), 6 deletions(-) > >> > > >> > diff --git a/gdb/target-float.c b/gdb/target-float.c > >> > index 39abb12696..0fd71c0dc3 100644 > >> > --- a/gdb/target-float.c > >> > +++ b/gdb/target-float.c > >> > @@ -1007,13 +1007,18 @@ host_float_ops::to_longest (const gdb_byte *addr, > >> > { > >> > T host_float; > >> > from_target (type, addr, &host_float); > >> > - /* Converting an out-of-range value is undefined behavior in C, but we > >> > - prefer to return a defined value here. */ > >> > - if (host_float > std::numeric_limits::max()) > >> > - return std::numeric_limits::max(); > >> > - if (host_float < std::numeric_limits::min()) > >> > + T min_possible_range = static_cast(std::numeric_limits::min()); > >> > + T max_possible_range = -min_possible_range; > >> > + /* host_float can be converted to an integer as long as it's in > >> > + the range [min_possible_range, max_possible_range). If not, it is either > >> > + too large, or too small, or is NaN; in this case return the maximum or > >> > + minimum possible value. */ > >> > + if (host_float < max_possible_range && host_float >= min_possible_range) > >> > + return static_cast (host_float); > >> > + if (host_float < min_possible_range) > >> > return std::numeric_limits::min(); > >> > - return (LONGEST) host_float; > >> > + /* This line will be executed if host_float is NaN. */ > >> > + return std::numeric_limits::max(); > >> > } > >> > > >> > /* Convert signed integer VAL to a target floating-number of type TYPE > >> > -- > >> > 2.23.0.187.g17f5b7556c-goog > >> >