From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 127297 invoked by alias); 26 Feb 2018 06:45:59 -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 127288 invoked by uid 89); 26 Feb 2018 06:45:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Feb 2018 06:45:57 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 9CFE71161E2; Mon, 26 Feb 2018 01:45:55 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id StsRB0GtboUY; Mon, 26 Feb 2018 01:45:55 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 2BF1C1161DF; Mon, 26 Feb 2018 01:45:55 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id D274D83054; Mon, 26 Feb 2018 10:45:50 +0400 (+04) Date: Mon, 26 Feb 2018 06:45:00 -0000 From: Joel Brobecker To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA v2 1/4] Sign-extend non-bit-fields in unpack_bits_as_long Message-ID: <20180226064550.jgquqtgf5en2bujm@adacore.com> References: <20180222203018.23551-1-tom@tromey.com> <20180222203018.23551-2-tom@tromey.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180222203018.23551-2-tom@tromey.com> User-Agent: NeoMutt/20170113 (1.7.2) X-SW-Source: 2018-02/txt/msg00372.txt.bz2 Hi Tom, On Thu, Feb 22, 2018 at 01:30:15PM -0700, Tom Tromey wrote: > unpack_bits_as_long is documented as sign-extending its result when > the type is signed. However, it was only doing sign-extension in the > case where the field was a bitfield -- that is, not when the "bitsize" > parameter was 0, indicating the size should be taken from the type. > > Also, unpack_bits_as_long was incorrectly computing the shift for > big-endian architectures for the non-bitfield case. > > This patch fixes these bugs in a straightforward way. A new selftest > is included. > > 2018-02-22 Tom Tromey > > * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add > unittests/unpack-selftests.c. > * unittests/unpack-selftests.c: New file. > * value.c (unpack_bits_as_long): Fix bugs in non-bitfield cases. Looks good to me. Just one thing: I think we need to adjust unpack_bits_as_long's documentation a bit to match the reality of how this function is called: /* Unpack a bitfield of the specified FIELD_TYPE, from the object at VALADDR, and store the result in *RESULT. The bitfield starts at BITPOS bits and contains BITSIZE bits. I checked the callers, and none of them really make a distinction between bitsize = 0 and bitsize != 0. And since it's fairly straightforward to handlet this case directly in unpack_bits_as_long, I agree this is best. Pre-approved with this change. Thanks for adding a self-test! -- Joel