[llvm-bugs] [Bug 44680] Optimizer breaks compare for the negation of the signed integer -0x80000000
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jan 27 09:10:18 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=44680
Dimitry Andric <dimitry at andric.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
CC| |dimitry at andric.com
Status|NEW |RESOLVED
--- Comment #1 from Dimitry Andric <dimitry at andric.com> ---
By negating what comes down to INT_MIN, you are invoking undefined behavior.
If you compile your program with -fsanitize-undefined, and run it, you will see
the following:
$ ./pr44680-ubsan
pr44680.cpp:5:20: runtime error: negation of -2147483648 cannot be represented
in type 'int'; cast to an unsigned type to negate this value to itself
-2147483648 Is NaN : true
-2147483648 < 0 : true
pr44680.cpp:13:30: runtime error: negation of -2147483648 cannot be represented
in type 'int'; cast to an unsigned type to negate this value to itself
pr44680.cpp:13:37: runtime error: negation of -2147483648 cannot be represented
in type 'int'; cast to an unsigned type to negate this value to itself
-2147483648 < 0 : true
See e.g. https://blog.regehr.org/archives/226 and
https://stackoverflow.com/a/37307948/6699433
--
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/20200127/8eb6c73a/attachment.html>
More information about the llvm-bugs
mailing list