On 12/10/16 18:59, Eric Botcazou wrote:
>> During the development of a patch I encountered some strange behavior
>> and decided to investigate. The result of which is I think I found a bug
>> with 'wide_int_storage::set_len' in gcc/wide-int.h.
>> The function reads:
>> inline void
>> wide_int_storage::set_len (unsigned int l, bool is_sign_extended)
>> {
>>   len = l;
>>   if (!is_sign_extended && len * HOST_BITS_PER_WIDE_INT > precision)
>>     val[len - 1] = sext_hwi (val[len - 1],
>>                              precision % HOST_BITS_PER_WIDE_INT);
>> }
> The code certainly lacks a comment explaining the apparent discrepancy.

It could do some comments yes. Also, it might also be worth changing the
comments on 'wide_int_storage::from':

/* Treat X as having signedness SGN and convert it to a PRECISION-bit
   number.  */
inline wide_int
wide_int_storage::from (const wide_int_ref &x, unsigned int precision,
                        signop sgn)
  wide_int result = wide_int::create (precision);
  result.set_len (wi::force_to_size (result.write_val (), x.val, x.len,
                                     x.precision, precision, sgn));
  return result;

If set_len really does 'ignore' signedness, then we are not treating X
as having signedness SGN. Right?


Reply via email to