<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 --- - Clang miscompiles the code with loop unrolling (-m32/-O2)"
   href="http://llvm.org/bugs/show_bug.cgi?id=19291">19291</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang miscompiles the code with loop unrolling (-m32/-O2)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>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>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>samsonov@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>eugeni.stepanov@gmail.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</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>