From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 66526 invoked by alias); 28 Aug 2019 08:29:41 -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 66516 invoked by uid 89); 28 Aug 2019 08:29:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-wm1-f68.google.com Received: from mail-wm1-f68.google.com (HELO mail-wm1-f68.google.com) (209.85.128.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 Aug 2019 08:29:39 +0000 Received: by mail-wm1-f68.google.com with SMTP id 10so1777623wmp.3 for ; Wed, 28 Aug 2019 01:29:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=jmVNW4hGpSuVgeP2gM91C2vGG4EyQduETgvwQOJydU8=; b=KNurorEXskpc/MH13RBu5Y0BLGkn9qmMi30vo7xsUwnGZW7KTE65+4opW4h7mJc2PE mVPDQ5qT287Ie0LaAypW24Y48ikrIoupV/jnzRFh4MM2PkNaT2RRQI7DcBtoeubJ48we dJuReP6i5qMl+5bY8jK6JkLGGUBx6O6QybAApINcwmIc/X5S3BCrqL4OHRr6sBq4nHr1 2GlX6HZp/vq0wgwcswt3DAIMTceSs4NLKpAn8ZFubbYyPCbZzR/AAICXXA5LPLgxZHtl U9nnz/GmC57laDO9jwgQ2dIMQ1yPIPxLGvnzSRuyCmxzYBq1vVmJaTDfdFSXKqBAYhDr Sg8w== Return-Path: Received: from localhost (host86-161-16-231.range86-161.btcentralplus.com. [86.161.16.231]) by smtp.gmail.com with ESMTPSA id c187sm3068707wmd.39.2019.08.28.01.29.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Aug 2019 01:29:36 -0700 (PDT) Date: Wed, 28 Aug 2019 08:29:00 -0000 From: Andrew Burgess To: Ali Tamur Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Fix float to LONGEST conversion. Message-ID: <20190828082935.GQ6076@embecosm.com> References: <20190828032808.242363-1-tamur@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190828032808.242363-1-tamur@google.com> X-Fortune: firewall needs cooling X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes X-SW-Source: 2019-08/txt/msg00627.txt.bz2 * 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 >