<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 --- - Loop miscompilation with -O3"
   href="http://llvm.org/bugs/show_bug.cgi?id=16177">16177</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Loop miscompilation with -O3
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </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>Loop Optimizer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>eugeni.stepanov@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>$ cat 1.cc
#include <stdio.h>

class S {
public:
  char x[1024];
};

S s[16];
S *p[16];

int main(void) {
  for (unsigned i = 0; i != 16; ++i) {
    p[i] = s + i;
  }
  for (unsigned i = 0; i != 16; ++i) {
    printf("%p\n", p[i]);
  }
  return 0;
}

$ clang++ -O3 1.cc -o 1
$ ./1
0x601030
0x601030
0x601830
0x601030
0x602030
0x601030
0x602830
0x601030
0x603030
0x601030
0x603830
0x601030
0x604030
0x601030
0x604830
0x601030


loop IR:
vector.body:                                      ; preds = %vector.body,
%vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %0 = getelementptr inbounds [16 x %class.S]* @s, i64 0, i64 %index
  %1 = insertelement <2 x %class.S*> undef, %class.S* %0, i32 0
  %2 = insertelement <2 x %class.S*> %1, %class.S* getelementptr ([16 x
%class.S]* @s, i64 0, i64 undef), i32 1
  %3 = getelementptr inbounds [16 x %class.S*]* @p, i64 0, i64 %index
  %4 = bitcast %class.S** %3 to <2 x %class.S*>*
  store <2 x %class.S*> %2, <2 x %class.S*>* %4, align 16
  %index.next = add i64 %index, 2
  %5 = icmp eq i64 %index.next, 16
  br i1 %5, label %for.cond2.preheader, label %vector.body


"undef" in "%2 =" line looks incorrect


Introduced in r182909.</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>