[llvm-bugs] [Bug 50581] New: Compiler "clang" makes optimization error (Ubuntu 20.04.2 LTS, clang version 10.0.0-4ubuntu1)

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jun 4 09:33:14 PDT 2021


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

            Bug ID: 50581
           Summary: Compiler "clang" makes optimization error (Ubuntu
                    20.04.2 LTS, clang version 10.0.0-4ubuntu1)
           Product: clang
           Version: 10.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: sergkryzh at gmail.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

Compiler "clang" makes an error when optimizing specific code (please note that
"Apple Clang" has the same problem under macOS). Below are steps to reproduce
the problem.
1. Create file "main.cpp" with such code:
#include <iostream>
class AnyClassOrType {
};
AnyClassOrType * GetPtr() {
    return nullptr;
}
AnyClassOrType & GetRef() {
    return *GetPtr();
}
int main(int argc, const char * argv[]) {
    AnyClassOrType *Ptr = GetPtr();
    AnyClassOrType *RefPtr = &GetRef();
    std::cout << std::boolalpha;
    std::cout << "nullptr == Ptr " << (nullptr == Ptr) << "\n"; // Debug &
Release: true
    std::cout << "nullptr == RefPtr " << (nullptr == RefPtr) << "\n"; // Debug:
true, Release: false (!)
    char Buffer[128];
    sprintf(Buffer, "RefPtr == %p", RefPtr); // Debug & Release: RefPtr ==
(nil)
    std::cout << Buffer << "\n";
    if(Ptr) { // Debug & Release: false
        std::cout << "if(Ptr) == true\n";
    }
    if(RefPtr) { // Debug: false, Release: true (!)
        std::cout << "if(RefPtr) == true\n";
    }
    return 0;
}
2. Build and run unoptimized (debug) and optimized (release) executables:
$ clang++ main.cpp -o debug
$ ./debug
$ clang++ -O2 main.cpp -o release
$ ./release
You will see that the output is different between them.

-- 
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/20210604/4f08e077/attachment.html>


More information about the llvm-bugs mailing list