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: unassignedclangb...@nondot.org
Reporter: sergkr...@gmail.com
CC: blitzrak...@gmail.com, dgre...@apple.com,
erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs