https://bugs.llvm.org/show_bug.cgi?id=40401

            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: unassignedclangb...@nondot.org
          Reporter: petr.azma...@wartsila.com
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@metafoo.co.uk

Created attachment 21362
  --> https://bugs.llvm.org/attachment.cgi?id=21362&action=edit
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to