<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - -O2/-O3 breaks reverse iterators"
href="http://llvm.org/bugs/show_bug.cgi?id=16421">16421</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-O2/-O3 breaks reverse iterators
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.3
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Keywords</th>
<td>miscompilation
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>a.luenser+llvmbugs@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>#include <cstddef>
#include <iostream>
#include <vector>
#include <numeric>
int main()
{
std::vector<double> wd(5);
std::iota(wd.rbegin(), wd.rend(), 1.0);
for (std::size_t i = 0; i < wd.size(); ++i)
std::cout << wd[i] << ", ";
for (std::ptrdiff_t i = wd.size() - 1; i >= 0; --i)
std::cout << wd[i] << ", ";
}
This code yields the expected result when compiled with -O1:
5, 4, 3, 2, 1, 1, 2, 3, 4, 5,
When compiling with -O2 or -O3, it breaks, however:
0, 4, 3, 2, 1, 1, 2, 3, 4, 5,
That's a pretty heavy bug if you ask me. It has affected me in a real
application.
Interestingly, if the two loops are interchanged, the bug disappears. The
sample is compiled correctly when using gcc 4.6, 4.7, 4.8 as well as Intel C++
13.1. It is also broken in Clang 3.2
Possible duplicate is <a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Reverse loop order with variable upper boundary not handled correctly by analyzer"
href="show_bug.cgi?id=12531">http://llvm.org/bugs/show_bug.cgi?id=12531</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>