This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

wi::max_value() of a boolean is not 1

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

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:

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?

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]