This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Update field offset/sizes when encountering artificial members such as vtable pointers
ClosedPublic

Authored by teemperor on Oct 28 2021, 2:22 AM.

Details

Summary

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.

Diff Detail

Event Timeline

teemperor created this revision.Oct 28 2021, 2:22 AM
teemperor requested review of this revision.Oct 28 2021, 2:23 AM
teemperor added inline comments.
lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py
165

The test changes are just fixing up the existing tests. It previously failed (it's hard to write XFAIL'ing tests when everything crashes)

teemperor retitled this revision from [lldb] Still update field offset/sizes for artificial members such as vtable pointers to [lldb] Update field offset/sizes when encountering artificial members such as vtable pointers.Oct 28 2021, 5:35 AM
labath accepted this revision.Oct 28 2021, 5:37 AM

You get a badge for writing a longer commit message than the patch itself.

This revision is now accepted and ready to land.Oct 28 2021, 5:37 AM