llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Windows] Assigning a base class pointer to a derived class causes an assertion in clang

Open stella.stamenova opened this issue 8 years ago • 6 comments

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:

  1. Build Clang on Windows with LLVM_ENABLE_ASSERTIONS=ON
  2. 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
}

stella.stamenova avatar Jun 26 '18 22:06 stella.stamenova

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

stella.stamenova avatar Jun 27 '18 20:06 stella.stamenova

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?

zmodem avatar Jun 27 '18 19:06 zmodem

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.

stella.stamenova avatar Jun 27 '18 16:06 stella.stamenova

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.

zmodem avatar Jun 27 '18 08:06 zmodem

@llvm/issue-subscribers-lldb

llvmbot avatar Jun 15 '23 20:06 llvmbot

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.

ZequanWu avatar Jun 15 '23 22:06 ZequanWu