<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><span class="vcard"><a class="email" href="mailto:dimitry@andric.com" title="Dimitry Andric <dimitry@andric.com>"> <span class="fn">Dimitry Andric</span></a>
</span> changed
<a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Optimizer breaks compare for the negation of the signed integer -0x80000000"
href="https://bugs.llvm.org/show_bug.cgi?id=44680">bug 44680</a>
<br>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>What</th>
<th>Removed</th>
<th>Added</th>
</tr>
<tr>
<td style="text-align:right;">Resolution</td>
<td>---
</td>
<td>INVALID
</td>
</tr>
<tr>
<td style="text-align:right;">CC</td>
<td>
</td>
<td>dimitry@andric.com
</td>
</tr>
<tr>
<td style="text-align:right;">Status</td>
<td>NEW
</td>
<td>RESOLVED
</td>
</tr></table>
<p>
<div>
<b><a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Optimizer breaks compare for the negation of the signed integer -0x80000000"
href="https://bugs.llvm.org/show_bug.cgi?id=44680#c1">Comment # 1</a>
on <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Optimizer breaks compare for the negation of the signed integer -0x80000000"
href="https://bugs.llvm.org/show_bug.cgi?id=44680">bug 44680</a>
from <span class="vcard"><a class="email" href="mailto:dimitry@andric.com" title="Dimitry Andric <dimitry@andric.com>"> <span class="fn">Dimitry Andric</span></a>
</span></b>
<pre>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. <a href="https://blog.regehr.org/archives/226">https://blog.regehr.org/archives/226</a> and
<a href="https://stackoverflow.com/a/37307948/6699433">https://stackoverflow.com/a/37307948/6699433</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>