[Bug middle-end/60814] incorrect integer promotion when multiplying unsigned short values
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Apr 11 00:16:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60814
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is undefined code as 0xffff*0xffff overflows int.
x * y is really
((int)x) * ((int)y)
So if that overflows and since we know that both (int)x and (int)y are both
positive integer since we are converting from unsigned short to int; the result
of ((int)x) * ((int)y) will also be positive (since overflow of signed integer
is undefined) we can remove the cast between int and unsigned int and go
directly to unsigned long long in a valid way.
More information about the Gcc-bugs
mailing list