<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - miscompilation: segfault with -O2"
   href="https://bugs.llvm.org/show_bug.cgi?id=38670">38670</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>miscompilation: segfault with -O2
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </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>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ohh.epicfail@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Using clang version 8.0.0 (trunk 340324) the following program crashes with
segfault with -O2. It looks like incorrect vectorization in asm. The problem
causes hand-made loop 'peeling' in example3 function. Also, clang 6.0.0 compile
this code incorrectly

#define N 1024
#define ALIGNED16 __attribute__((aligned(16)))
int ia[N] ALIGNED16;
int ib[N] ALIGNED16;

void init_memory(void *start, void *end) {
  unsigned char state = 1;
  while (start != end) {
    state *= 7;
    state ^= 0x27;
    state += 1;
    *((unsigned char *)start) = state;
    start = ((char *)start) + 1;
  }
}

typedef int aint __attribute__((__aligned__(16)));
__attribute__((noinline)) void example3(int n, aint *__restrict__ p,
                                        aint *__restrict q) {

  n--;
  *p++ = *q++;
  while (n--) {
    *p++ = *q++;
  }
}

int main() {
  init_memory(&ia[0], &ia[N]);
  init_memory(&ib[0], &ib[N]);

  example3(N, ia, ib);

  return 0;
}</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>