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

[Bug middle-end/60814] incorrect integer promotion when multiplying unsigned short values


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.


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