<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 - Incorrect code generation with -02"
   href="https://bugs.llvm.org/show_bug.cgi?id=40401">40401</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Incorrect code generation with -02
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>7.0
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>petr.azmanov@wartsila.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21362" name="attach_21362" title="Test program source">attachment 21362</a> <a href="attachment.cgi?id=21362&action=edit" title="Test program source">[details]</a></span>
Test program source

Overview:

Attached is a reduced serialization code snippet. The program compares instance
of struct test_t with the result of deserialization of the same struct from
binary data and outputs the result of this comparison.

Program returns incorrect result. Doesn't happen when -O1 or lower is used. The
test code is probably specific to x86_64. AFAIK the code doesn't contain UB.

Steps to Reproduce:

Run the following script (see attachments):

#!/bin/bash
clang++ -O2 -std=c++11 testfail.cpp
echo -ne "clang: "
./a.out || echo -ne OK
echo -ne "\ngcc: "
g++ -O2 -std=c++11 testfail.cpp
./a.out || echo -ne OK

Actual Results:

Output:
clang: 
gcc: OK

Expected Results:

Expected output:
clang: OK
gcc: OK

Build Date & Hardware:

clang version 7.0.1 (tags/RELEASE_701/final)
x86_64
Linux archlinux 4.20.0-arch1-1-ARCH

Additional Builds and Platforms:

Checked with clang version 7.0.0 with the same result.

Additional Info:

Checked with -std=c++14 and -std=c++17 with the same result.

Test sample contains commented code with slightly different comparisons. Only
one of them results in correct code generation.

godbolt.org outputs trivial main returning constant for versions 5, 6, 7 and
trunk.</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>