<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 - Clang produces incorrect code with -O2 and higher"
   href="https://bugs.llvm.org/show_bug.cgi?id=37748">37748</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang produces incorrect code with -O2 and higher
          </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>Windows NT
          </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>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>Vsevolod.Livinskij@frtk.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=20413" name="attach_20413" title="Reproducer.">attachment 20413</a> <a href="attachment.cgi?id=20413&action=edit" title="Reproducer.">[details]</a></span>
Reproducer.

Clang miscompiles with -O2 and higher.
opt-bisect-limit points to CodeGen Prepare on function

Reproducer:
<span class="quote">>$ cat func.c</span >
extern long a;
extern long b;
extern unsigned short c;
extern long d;
extern short e;

void foo() {
  a = (short)(e | (c & -32692));
  if (c / d)
    b = (e | (c & -32692)) > 0;
}
<span class="quote">>$ cat driver.c</span >
#include <stdio.h>

long a, b;
unsigned short c = 43589;
long d = 3;
short e;

void foo();

int main() {
  foo();
  printf("%ld\n", a);
}

Error:
<span class="quote">>$ clang driver.c func.c ; ./a.out</span >
-32700
<span class="quote">>$ clang -O2 driver.c func.c ; ./a.out</span >
32836

LLVM version:
clang version 7.0.0 (trunk 334268)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /llvm/bin-trunk/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64</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>