[llvm-bugs] [Bug 40401] New: Incorrect code generation with -02

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 22 04:46:34 PST 2019


            Bug ID: 40401
           Summary: Incorrect code generation with -02
           Product: clang
           Version: 7.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: petr.azmanov at wartsila.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Created attachment 21362
  --> https://bugs.llvm.org/attachment.cgi?id=21362&action=edit
Test program source


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):

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:

gcc: OK

Expected Results:

Expected output:
clang: OK
gcc: OK

Build Date & Hardware:

clang version 7.0.1 (tags/RELEASE_701/final)
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

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190122/38b7aec9/attachment.html>

More information about the llvm-bugs mailing list