[Windows] Assigning a base class pointer to a derived class causes an assertion in clang
| Bugzilla Link | 37947 |
| Version | trunk |
| OS | Windows NT |
| CC | @zmodem |
Extended Description
This reproduces when trying to run one of the LLDB tests on Windows (specifically, TestCallOverriddenMethod.py).
To reproduce:
- Build Clang on Windows with LLVM_ENABLE_ASSERTIONS=ON
- Build the source for TestCallOverriddenMethod.py
Result:
Assertion failed: Prior->Kind == MemberInfo::Field && !Prior->FD && "Only storage fields have tail padding!", file e:_work\1\s\llvm\tools\clang\lib\codegen\cgrecordlayoutbuilder.cpp, line 596
The source for the test is:
class Base {
public:
virtual ~Base() {}
virtual void foo() {}
};
class Derived : public Base {
public:
virtual void foo() {}
};
int main() {
Derived d;
Base *b = &d;
return 0; // Set breakpoint here
}
I see what you mean. I had assumed that the assert fired when clang tried to build the source since it's in source from the clang repo, but after looking into it further to get the right build commands for you, I realized that's not the case. It looks like the bug should maybe be assigned to LLDB.
Here are the build commands:
clang.exe -std=c++14 -g -O0 -fno-builtin -m64 -fno-limit-debug-info -fno-exceptions -D_HAS_EXCEPTIONS=0 -fms-compatibility-version=19.0 -c -o main.o main.cpp
clang.exe main.o -g -O0 -fno-builtin -m64 -fuse-ld=lld --driver-mode=g++ -o "a.out"
Then to get to the assert:
Run lldb.exe, and execute:
file a.out breakpoint set -f main.cpp -l 15 run expr b->foo()
I meant the arguments passed to the compiler when trying the source code you quoted. Is it possible to share those?
Or does the assert fire first when lldb tries to debug the code?
We use the latest source for clang directly from the mainline clang repositories.
Here's out CMAKE command:
-DPYTHON_HOME=C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64 -DCMAKE_BUILD_TYPE=Release -G Visual Studio 15 2017 Win64 -Thost=x64 -DLLVM_ENABLE_ASSERTIONS=ON
That means that we end up using 64bit release clang (and not clang-cl) for the compilation of the LLDB tests.
Can you share what Clang version you used, and the arguments passed to the compiler?
I just tried "clang-cl /c a.cc" on the source code you quoted, and it doesn't reproduce the problem.
@llvm/issue-subscribers-lldb
It no longer crashes in latest lldb and gives the correct result if let foo() to return different values in base class and derived class. I guess it's already fixed.