[LLVMbugs] [Bug 16642] Optimization eliminates an overflow check.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 17 06:15:20 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16642

Duncan Sands <baldrick at free.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |baldrick at free.fr
         Resolution|---                         |INVALID

--- Comment #1 from Duncan Sands <baldrick at free.fr> ---
Overflow when multiplying two signed numbers results in undefined behaviour
according to the C standard.  Thus the compiler is free to introduce code that
fires a nuclear missile, wipes your hard-drive etc, if the multiplication does
in fact overflow.  Fortunately the compiler only inserted code that sets err to
zero in this case, phew!

As overflow when multiplying unsigned numbers does not result in undefined
behaviour you can fix your code by replacing
  r = x * y;
with
  r = (long long)((unsigned long long)x * (unsigned long long)y);

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130717/5bead4ea/attachment.html>


More information about the llvm-bugs mailing list