[cherry-pick][swift/releas/5.9] [lldb][DWARFASTParserClang] Don't create unnamed bitfields to account for vtable pointer #6865
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When filling out the LayoutInfo for a structure with the offsets
from DWARF, LLDB fills gaps in the layout by creating unnamed
bitfields and adding them to the AST. If we don't do this correctly
and our layout has overlapping fields, we will hat an assertion
in
clang::CGRecordLowering::lower()
. Specifically, if we havea derived class with a VTable and a bitfield immediately following
the vtable pointer, we create a layout with overlapping fields.
This is an oversight in some of the previous cleanups done around this
area.
In
D76808
, we prevented LLDB from creating unnamed bitfields if therewas a gap between the last field of a base class and the start of a bitfield
in the derived class.
In
D112697
, we started accounting for the vtable pointer. The intentionthere was to make sure the offset bookkeeping accounted for the
existence of a vtable pointer (but we didn't actually want to create
any AST nodes for it). Now that
last_field_info.bit_size
was beingset even for artifical fields, the previous fix
D76808
brokespecifically for cases where the bitfield was the first member of a
derived class with a vtable (this scenario wasn't tested so we didn't
notice it). I.e., we started creating redundant unnamed bitfields for
where the vtable pointer usually sits. This confused the lowering logic
in clang.
This patch adds a condition to
ShouldCreateUnnamedBitfield
whichchecks whether the first field in the derived class is a vtable ptr.
Testing
Differential Revision: https://reviews.llvm.org/D150591
(cherry picked from commit 3c30f224005e3749c89e00592bd2a43aba2aaf75)