This is the mail archive of the gcc@gcc.gnu.org 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]

Re: When to ingore signed vs. unsigned comparison?


> The question simplified boils down to: given two trees a and b
> with one of them being an (signed or unsigned) integer constant,
> when and how do I convert the integer constant to the type of
> the other tree?  The simplest case would be f.i. int i and 5U
> - how do I check that it is legal to convert 5U to int, and how
> do I do this?
>
> Using fold_convert_const_int_from_int and checking TREE_CONSTANT_OVERFLOW
> on the result doesn't work - I get 0fffffffb from -5 to unsinged
> and no overflow set.

Conversions from signed to unsigned cause no overflow, so I think for
these conversions, you have to do the range check separately.
If you don't convert to a smaller mode, that should be just
a check that the value is greater than or equal to zero.

OTOH, unsigned->signed conversions should cause overflow when the
destination type can't represent the value.


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