This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: wi::max_value() of a boolean is not 1
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: gcc at gcc dot gnu dot org,Aldy Hernandez <aldyh at redhat dot com>,GCC Mailing List <gcc at gcc dot gnu dot org>
- Cc: Andrew MacLeod <amacleod at redhat dot com>
- Date: Sun, 20 Aug 2017 12:40:30 +0200
- Subject: Re: wi::max_value() of a boolean is not 1
- Authentication-results: sourceware.org; auth=none
- References: <41bd9f11-ec77-acbd-d5a3-481ec33d15dc@redhat.com>
On August 20, 2017 10:46:54 AM GMT+02:00, Aldy Hernandez <aldyh@redhat.com> wrote:
>Hi folks.
>
>Calling wi::max_value() of a boolean_type creates a wide_int with all
>bits set, not just the least significant bit.
>
>tree type = boolean_type_node;
>wide_int x = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
>(gdb) print x.dump()
>[0xffffffffffffffff], precision = 1
>
>However, one can also create a boolean of true with:
>
>wide_int one = wi::uhwi (1, TYPE_PRECISION (boolean_type_node));
>(gdb) print one.dump()
>[0x1], precision = 1
Looks like this one fails to be sign extended.
Richard.
>These will not be equal to each other because wi::eq_p() will only
>strip
>off excess bits when <is_sign_extended=false>. However,
>is_sign_extended=true for all wide_int's.
>
>Am I doing something wrong?
>
>Could I change wi::max_value() to strip off excess bits, instead of
>setting all bits like it's currently doing:
>
>wide_int
>wi::max_value (unsigned int precision, signop sgn)
>{
> gcc_checking_assert (precision != 0);
> if (sgn == UNSIGNED)
> /* The unsigned max is just all ones. */
> return shwi (-1, precision);
>...
>...
>
>Or perhaps change wi::eq_p() to strip off excess bits?
>
>Or am I missing something else entirely?
>Aldy