This is the mail archive of the gcc-patches@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: [PATCH] Fix PR32628, bogus overflow flag on sizetype consts


On Tue, 15 Jan 2008, Richard Kenner wrote:

> > 	* fold-const.c (fold_convert_const_int_from_int): Do not
> > 	set overflow if that occured only because of a sign extension
> > 	change when converting from/to a sizetype with the same
> > 	precision.
> 
> Well certainly converting *to* a sizetype shouldn't set TREE_OVERFLOW,
> but I don't understand why converting *from* a sizetype shouldn't set it
> if we otherwise would be setting it.  Can you explain?

Well, because you don't know whether the sizetype value is to be
treated as signed or unsigned, so we just assume it has the same
signedness as the target type.  Remember, we are only speaking
of the case where we convert type A to type B and the precision
of type A is equal to that of B.

So, if you convert 0xffffffffu to sizetype the constant will get
sign-extended (sizetypes are sign extended always) and the result
will not get the overflow flag set.  If you convert that value
back to unsigned long, the value will be again zero-extended
(and you shouldn't get the overflow flag set, as it wasn't set
originally).

Now, we cannot distinguish this case (originally unsigned constant)
from the case where the constant is originally signed.  For this
reason I think symmetry is what is the most useful semantics.

Richard.


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