[lldb] Update field offset/sizes when encountering artificial members such as vtable...
authorRaphael Isemann <teemperor@gmail.com>
Sat, 30 Oct 2021 11:13:57 +0000 (13:13 +0200)
committerRaphael Isemann <teemperor@gmail.com>
Sat, 30 Oct 2021 11:22:21 +0000 (13:22 +0200)
commite2ede1715d4141279bb76d8850e0494b85d1eee8
tree32001a4ddddc01d950e36cc49caa31194de7e03b
parentaa2d3b59ce75a5808f2fe3f2010920c1e19711bf
[lldb] Update field offset/sizes when encountering artificial members such as vtable pointers

`DWARFASTParserClang::ParseSingleMember` turns DWARF DIEs that describe
struct/class members into their respective Clang representation (e.g.,
clang::FieldDecl). It also updates a record of where the last field
started/ended so that we can speculatively fill any holes between a field and a
bitfield with unnamed bitfield padding.

Right now we are completely ignoring 'artificial' members when parsing the DWARF
of a struct/class. The only artificial member that seems to be emitted in
practice for C/C++ seems to be the vtable pointer.

By completely skipping both the Clang AST node creation and the updating of the
last-field record, we essentially leave a hole in our layout with the size of
our artificial member. If the next member is a bitfield we then speculatively
fill the hole with an unnamed bitfield. During CodeGen Clang inserts an
artificial vtable pointer into the layout again which now occupies the same
offset as the unnamed bitfield. This later brings down Clang's
`CGRecordLowering::insertPadding` when it checks that none of the fields of the
generated record layout overlap.

Note that this is not a Clang bug. We explicitly set the offset of our fields in
LLDB and overwrite whatever Clang makes up.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D112697
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py
lldb/test/API/lang/cpp/bitfields/main.cpp