This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] avoid printing leading 0 in widest_int hex dumps
- From: Richard Sandiford <richard dot sandiford at linaro dot org>
- To: Aldy Hernandez <aldyh at redhat dot com>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>, Andrew MacLeod <amacleod at redhat dot com>
- Date: Tue, 17 Oct 2017 13:18:12 +0100
- Subject: Re: [patch] avoid printing leading 0 in widest_int hex dumps
- Authentication-results: sourceware.org; auth=none
- References: <d935df71-7e0d-65fc-0321-d919983641be@redhat.com>
Aldy Hernandez <aldyh@redhat.com> writes:
> Hi folks!
>
> Calling print_hex() on a widest_int with the most significant bit turned
> on can lead to a leading zero being printed (0x0ffff....). This produces
> confusing dumps to say the least, especially when you incorrectly assume
> an integer is NOT signed :).
That's the intended behaviour though. wide_int-based types only use as
many HWIs as they need to store their current value, with any other bits
in the value being a sign extension of the top bit. So if the most
significant HWI in a widest_int is zero, that HWI is there to say that
the previous HWI should be zero- rather than sign-extended.
So:
0x0ffffffff -> (1 << 32) - 1 to infinite precision
(i.e. a positive value)
0xffffffff -> -1
Thanks,
Richard