tech-toolchain archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: gcc unsigned vs signed compare
On Aug 31, 2011, at 1:56 PM, Christos Zoulas wrote:
> In article <20110831202534.GA7800%antioche.eu.org@localhost>,
> Manuel Bouyer <bouyer%antioche.eu.org@localhost> wrote:
>> Hello,
>> I tracked down a bug on a mips64el platform (see PR 45310), which turns out
>> to be a signed vs unsigned compare issue.
>>
>> In lib/libc/gen/fixunsgen_ieee754.c there is a compare:
>> (exp - mant_dig > sizeof(UINTXX_T)*8-1)
>> exp is int, mant_dig is size_t (unsigned long) and sizeof returns size_t.
>> gcc generates an unsigned compare for this, which doesn't gives the expected
>> result when exp < mant_dig. Is gcc right when generating an unsigned
>> compare here ?
>
> Yes, the promotion rule is signed -> unsigned.
I fixed this by changing it to
((size_t)exp >= mant_dig + sizeof(UINTXX_T)*8)
which also handles the the (exp < 0 || ...) before that.
Home |
Main Index |
Thread Index |
Old Index