summaryrefslogtreecommitdiff
path: root/lldb
diff options
context:
space:
mode:
authorMichael Buch <michaelbuch12@gmail.com>2023-05-15 15:31:14 +0100
committerMichael Buch <michaelbuch12@gmail.com>2023-05-16 11:18:09 +0100
commit56eff197d0d629c768e8e48fb995e8a1d2cd6441 (patch)
tree8ff599492b09a547694da5fe3dccc0c5cd404914 /lldb
parentca64f9af04472a27656d84c06f4e332ebbf14b4d (diff)
downloadllvm-56eff197d0d629c768e8e48fb995e8a1d2cd6441.tar.gz
[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
Diffstat (limited to 'lldb')
-rw-r--r--lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp40
-rw-r--r--lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h16
2 files changed, 44 insertions, 12 deletions
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 7f67d25f58ae..db3213aebdfb 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2892,18 +2892,8 @@ void DWARFASTParserClang::ParseSingleMember(
last_field_end += word_width - (last_field_end % word_width);
}
- // If we have a gap between the last_field_end and the current
- // field we have an unnamed bit-field.
- // If we have a base class, we assume there is no unnamed
- // bit-field if this is the first field since the gap can be
- // attributed to the members from the base class. This assumption
- // is not correct if the first field of the derived class is
- // indeed an unnamed bit-field. We currently do not have the
- // machinary to track the offset of the last field of classes we
- // have seen before, so we are not handling this case.
- if (this_field_info.bit_offset > last_field_end &&
- !(last_field_info.bit_offset == 0 && last_field_info.bit_size == 0 &&
- layout_info.base_offsets.size() != 0)) {
+ if (ShouldCreateUnnamedBitfield(last_field_info, last_field_end,
+ this_field_info, layout_info)) {
unnamed_field_info = FieldInfo{};
unnamed_field_info->bit_size =
this_field_info.bit_offset - last_field_end;
@@ -3698,3 +3688,29 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes(
return !failures.empty();
}
+
+bool DWARFASTParserClang::ShouldCreateUnnamedBitfield(
+ FieldInfo const &last_field_info, uint64_t last_field_end,
+ FieldInfo const &this_field_info,
+ lldb_private::ClangASTImporter::LayoutInfo const &layout_info) const {
+ // If we have a gap between the last_field_end and the current
+ // field we have an unnamed bit-field.
+ if (this_field_info.bit_offset <= last_field_end)
+ return false;
+
+ // If we have a base class, we assume there is no unnamed
+ // bit-field if this is the first field since the gap can be
+ // attributed to the members from the base class. This assumption
+ // is not correct if the first field of the derived class is
+ // indeed an unnamed bit-field. We currently do not have the
+ // machinary to track the offset of the last field of classes we
+ // have seen before, so we are not handling this case.
+ const bool have_base = layout_info.base_offsets.size() != 0;
+ const bool this_is_first_field =
+ last_field_info.bit_offset == 0 && last_field_info.bit_size == 0;
+
+ if (have_base && this_is_first_field)
+ return false;
+
+ return true;
+}
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
index a4613afafd54..9edf718ba921 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -236,6 +236,22 @@ private:
}
};
+ /// Returns 'true' if we should create an unnamed bitfield
+ /// and add it to the parser's current AST.
+ ///
+ /// \param[in] last_field_info FieldInfo of the previous DW_TAG_member
+ /// we parsed.
+ /// \param[in] last_field_end Offset (in bits) where the last parsed field
+ /// ended.
+ /// \param[in] this_field_info FieldInfo of the current DW_TAG_member
+ /// being parsed.
+ /// \param[in] layout_info Layout information of all decls parsed by the
+ /// current parser.
+ bool ShouldCreateUnnamedBitfield(
+ FieldInfo const &last_field_info, uint64_t last_field_end,
+ FieldInfo const &this_field_info,
+ lldb_private::ClangASTImporter::LayoutInfo const &layout_info) const;
+
/// Parses a DW_TAG_APPLE_property DIE and appends the parsed data to the
/// list of delayed Objective-C properties.
///