<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><span class="vcard"><a class="email" href="mailto:dblaikie@gmail.com" title="David Blaikie <dblaikie@gmail.com>"> <span class="fn">David Blaikie</span></a>
</span> changed
<a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Clang optimizer leads to wrong if-clause result"
href="https://bugs.llvm.org/show_bug.cgi?id=46710">bug 46710</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;">Status</td>
<td>NEW
</td>
<td>RESOLVED
</td>
</tr>
<tr>
<td style="text-align:right;">CC</td>
<td>
</td>
<td>dblaikie@gmail.com
</td>
</tr></table>
<p>
<div>
<b><a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Clang optimizer leads to wrong if-clause result"
href="https://bugs.llvm.org/show_bug.cgi?id=46710#c1">Comment # 1</a>
on <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Clang optimizer leads to wrong if-clause result"
href="https://bugs.llvm.org/show_bug.cgi?id=46710">bug 46710</a>
from <span class="vcard"><a class="email" href="mailto:dblaikie@gmail.com" title="David Blaikie <dblaikie@gmail.com>"> <span class="fn">David Blaikie</span></a>
</span></b>
<pre><span class="quote">> All of these may drive programmers' attention to undefined behaviors and they may spend a lot of time looking at their codes trying to find out any of those, which actually is not an undefined behavior.</span >
But this is undefined behavior - integer overflow is UB in C++.
Clang's Undefined Behavior Sanitizer detects this:
$ cat > test.cpp
#include <iostream>
int main()
{
int a; // Enter 2000000000 (2*10^9)
int b; // Enter 1000000000 (10^9)
std::cin >> a >> b;
if (a + b >= a)
std::cout << "Yes" << std::endl;
else
std::cout << "No" << std::endl;
}
$ clang++ -fsanitize=undefined test.cpp -g
$ echo "2000000000 1000000000" | ./a.out
test.cpp:9:11: runtime error: signed integer overflow: 2000000000 + 1000000000
cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior test.cpp:9:11 in
No</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>