This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: When to ingore signed vs. unsigned comparison?
- From: Joern RENNECKE <joern dot rennecke at st dot com>
- To: Richard at st dot com, Guenther at st dot com
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 08 Feb 2005 12:50:39 +0000
- Subject: 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.