Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA v2 1/4] Sign-extend non-bit-fields in unpack_bits_as_long
Date: Mon, 26 Feb 2018 06:45:00 -0000	[thread overview]
Message-ID: <20180226064550.jgquqtgf5en2bujm@adacore.com> (raw)
In-Reply-To: <20180222203018.23551-2-tom@tromey.com>

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  <tom@tromey.com>
> 
> 	* 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


  reply	other threads:[~2018-02-26  6:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-22 20:30 [RFA v2 0/4] variants and variant parts Tom Tromey
2018-02-22 20:30 ` [RFA v2 4/4] Handle DW_TAG_variant_part and DW_TAG_variant Tom Tromey
2018-02-26  6:56   ` Joel Brobecker
2018-02-26 16:16     ` Tom Tromey
2018-02-22 20:30 ` [RFA v2 1/4] Sign-extend non-bit-fields in unpack_bits_as_long Tom Tromey
2018-02-26  6:45   ` Joel Brobecker [this message]
2018-02-22 20:30 ` [RFA v2 2/4] Initial support for variant parts Tom Tromey
2018-02-26  6:49   ` Joel Brobecker
2018-02-22 20:30 ` [RFA v2 3/4] Convert Rust to use discriminated unions Tom Tromey
2018-02-26  6:50   ` Joel Brobecker
2018-02-27 23:23   ` Pedro Alves
2018-02-28  0:23     ` Tom Tromey
2018-04-10 20:36   ` -readnow crash Rust regression [Re: [RFA v2 3/4] Convert Rust to use discriminated unions] Jan Kratochvil
2018-04-11  2:52     ` Tom Tromey
2018-04-11  7:04       ` Jan Kratochvil
2018-04-11 19:49         ` Tom Tromey
2018-04-12 18:10           ` Tom Tromey
2018-04-12 18:45             ` Keith Seitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180226064550.jgquqtgf5en2bujm@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox