[LLVMbugs] [Bug 16421] New: -O2/-O3 breaks reverse iterators

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Jun 22 12:15:11 PDT 2013


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: unassignedclangbugs at nondot.org
          Reporter: a.luenser+llvmbugs at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130622/41607c5c/attachment.html>


More information about the llvm-bugs mailing list