http://llvm.org/bugs/show_bug.cgi?id=16421
Bug ID: 16421
Summary: -O2/-O3 breaks reverse iterators
Product: clang
Version: 3.3
Hardware: PC
OS: Linux
Status: NEW
Keywords: miscompilation
Severity: normal
Priority: P
Component: -New Bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
Classification: Unclassified
#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 http://llvm.org/bugs/show_bug.cgi?id=12531
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs