<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 - Wrong constant folding"
   href="https://bugs.llvm.org/show_bug.cgi?id=35240">35240</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrong constant folding
          </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>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>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>ishiura-compiler@ml.kwansei.ac.jp
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>LLVM + clang 6.0 for x86_64 miscompiles the following code.

% cat test.c
volatile int buff = 0;
void PRINTF(const int* s)
{
  while(*s++) buff = *s;
}

char a = 0;
char b = 0;
short c = 0;
int d = 0;
int e = 0;

int main (void)
{
  volatile short f = 1;
  volatile int g = 1;
  int h = ( 1 << c ) & 3;
  a = 0 == g;
  int i = 1 == g;
  volatile int j = ((long)3>>g)%3;
  volatile int k = (1*i)>>c;
  c = a|f;
  e = 3<<a;
  b = d*i;
  int l = (3>>a)/3;
  if (h != 1) { PRINTF((const int*)&h); }
  if (c != 1) __builtin_abort();
  if (l != 1) __builtin_abort();
  return 0;
}

% clang-6.0 -O1 test.c
% ./a.out
zsh: abort (core dumped)  ./a.out
% clang-6.0 -O2 test.c
% ./a.out
zsh: abort (core dumped)  ./a.out
% clang-6.0 -O3 test.c
% ./a.out
zsh: abort (core dumped)  ./a.out
% clang-6.0 -Os test.c
% ./a.out
zsh: abort (core dumped)  ./a.out
% clang-6.0 -v
clang version 6.0.0 (trunk 317078)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
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>