[LLVMbugs] [Bug 19291] New: Clang miscompiles the code with loop unrolling (-m32/-O2)

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Mar 31 06:26:47 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=19291

            Bug ID: 19291
           Summary: Clang miscompiles the code with loop unrolling
                    (-m32/-O2)
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: samsonov at google.com
                CC: eugeni.stepanov at gmail.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Reproduces with trunk Clang for me:
$ cat test.cc 
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

template <unsigned long bvsize>
void Test() {
  vector<unsigned long> bits(bvsize);

  for (unsigned long it = 0; it < 30; it++) {
    for (unsigned long j = 0; j < bits.size(); j++) {
      bits[j] = j;
    }
    for (size_t j = 0; j < bits.size(); j++) {
      if (j != bits[j]) {
        fprintf(stderr, "%zu:%lu\n", j, bits[j]);
        abort();
      }
    }
  }
}

int main(int argc, char **argv) {

  Test<8>();
  Test<16>();
  Test<32>();
  Test<64>();

  return 0;
}

$ bin/clang -fPIC -O2 -m32 -lstdc++ test.cc && ./a.out
0:980777509
Aborted (core dumped)

The problem goes away if I remove -fPIC or -m32, or reduce the number of Test<>
instantiations.

-- 
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/20140331/7927354f/attachment.html>


More information about the llvm-bugs mailing list