Skip to content

Commit 4c5a02c

Browse files
committed
[lldb][DWARFASTParserClang][NFC] Extract condition for unnamed bitfield creation into helper function
This patch adds a new private helper `DWARFASTParserClang::ShouldCreateUnnamedBitfield` which `ParseSingleMember` whether we should fill the current gap in a structure layout with unnamed bitfields. Extracting this logic will allow us to add additional conditions in upcoming patches without jeoperdizing readability of `ParseSingleMember`. We also store some of the boolean conditions in local variables to make the intent more obvious. Differential Revision: https://reviews.llvm.org/D150590 (cherry picked from commit 56eff19)
1 parent 79b9ed6 commit 4c5a02c

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,18 +2852,8 @@ void DWARFASTParserClang::ParseSingleMember(
28522852
last_field_end += word_width - (last_field_end % word_width);
28532853
}
28542854

2855-
// If we have a gap between the last_field_end and the current
2856-
// field we have an unnamed bit-field.
2857-
// If we have a base class, we assume there is no unnamed
2858-
// bit-field if this is the first field since the gap can be
2859-
// attributed to the members from the base class. This assumption
2860-
// is not correct if the first field of the derived class is
2861-
// indeed an unnamed bit-field. We currently do not have the
2862-
// machinary to track the offset of the last field of classes we
2863-
// have seen before, so we are not handling this case.
2864-
if (this_field_info.bit_offset > last_field_end &&
2865-
!(last_field_info.bit_offset == 0 && last_field_info.bit_size == 0 &&
2866-
layout_info.base_offsets.size() != 0)) {
2855+
if (ShouldCreateUnnamedBitfield(last_field_info, last_field_end,
2856+
this_field_info, layout_info)) {
28672857
unnamed_field_info = FieldInfo{};
28682858
unnamed_field_info->bit_size =
28692859
this_field_info.bit_offset - last_field_end;
@@ -3657,3 +3647,29 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes(
36573647

36583648
return !failures.empty();
36593649
}
3650+
3651+
bool DWARFASTParserClang::ShouldCreateUnnamedBitfield(
3652+
FieldInfo const &last_field_info, uint64_t last_field_end,
3653+
FieldInfo const &this_field_info,
3654+
lldb_private::ClangASTImporter::LayoutInfo const &layout_info) const {
3655+
// If we have a gap between the last_field_end and the current
3656+
// field we have an unnamed bit-field.
3657+
if (this_field_info.bit_offset <= last_field_end)
3658+
return false;
3659+
3660+
// If we have a base class, we assume there is no unnamed
3661+
// bit-field if this is the first field since the gap can be
3662+
// attributed to the members from the base class. This assumption
3663+
// is not correct if the first field of the derived class is
3664+
// indeed an unnamed bit-field. We currently do not have the
3665+
// machinary to track the offset of the last field of classes we
3666+
// have seen before, so we are not handling this case.
3667+
const bool have_base = layout_info.base_offsets.size() != 0;
3668+
const bool this_is_first_field =
3669+
last_field_info.bit_offset == 0 && last_field_info.bit_size == 0;
3670+
3671+
if (have_base && this_is_first_field)
3672+
return false;
3673+
3674+
return true;
3675+
}

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,22 @@ class DWARFASTParserClang : public DWARFASTParser {
219219
}
220220
};
221221

222+
/// Returns 'true' if we should create an unnamed bitfield
223+
/// and add it to the parser's current AST.
224+
///
225+
/// \param[in] last_field_info FieldInfo of the previous DW_TAG_member
226+
/// we parsed.
227+
/// \param[in] last_field_end Offset (in bits) where the last parsed field
228+
/// ended.
229+
/// \param[in] this_field_info FieldInfo of the current DW_TAG_member
230+
/// being parsed.
231+
/// \param[in] layout_info Layout information of all decls parsed by the
232+
/// current parser.
233+
bool ShouldCreateUnnamedBitfield(
234+
FieldInfo const &last_field_info, uint64_t last_field_end,
235+
FieldInfo const &this_field_info,
236+
lldb_private::ClangASTImporter::LayoutInfo const &layout_info) const;
237+
222238
/// Parses a DW_TAG_APPLE_property DIE and appends the parsed data to the
223239
/// list of delayed Objective-C properties.
224240
///

0 commit comments

Comments
 (0)