-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb][DWARFASTParserClang][NFC] Factor out unnamed bitfield creation into helper #108196
Merged
Michael137
merged 7 commits into
llvm:main
from
Michael137:bugfix/lldb-nua-unnamed-bitfields
Sep 12, 2024
Merged
[lldb][DWARFASTParserClang][NFC] Factor out unnamed bitfield creation into helper #108196
Michael137
merged 7 commits into
llvm:main
from
Michael137:bugfix/lldb-nua-unnamed-bitfields
Sep 12, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesThis logic will need adjusting soon for #108155 This patch pulls out the logic for detecting/creating unnamed bitfields out of Full diff: https://github.com/llvm/llvm-project/pull/108196.diff 2 Files Affected:
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 4d688f9a1358b2..4f651a78f67918 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2858,7 +2858,6 @@ void DWARFASTParserClang::ParseSingleMember(
}
const uint64_t character_width = 8;
- const uint64_t word_width = 32;
CompilerType member_clang_type = member_type->GetLayoutCompilerType();
const auto accessibility = attrs.accessibility == eAccessNone
@@ -2926,40 +2925,10 @@ void DWARFASTParserClang::ParseSingleMember(
detect_unnamed_bitfields =
die.GetCU()->Supports_unnamed_objc_bitfields();
- if (detect_unnamed_bitfields) {
- std::optional<FieldInfo> unnamed_field_info;
- uint64_t last_field_end =
- last_field_info.bit_offset + last_field_info.bit_size;
-
- if (!last_field_info.IsBitfield()) {
- // The last field was not a bit-field...
- // but if it did take up the entire word then we need to extend
- // last_field_end so the bit-field does not step into the last
- // fields padding.
- if (last_field_end != 0 && ((last_field_end % word_width) != 0))
- last_field_end += word_width - (last_field_end % word_width);
- }
-
- 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;
- unnamed_field_info->bit_offset = last_field_end;
- }
-
- if (unnamed_field_info) {
- clang::FieldDecl *unnamed_bitfield_decl =
- TypeSystemClang::AddFieldToRecordType(
- class_clang_type, llvm::StringRef(),
- m_ast.GetBuiltinTypeForEncodingAndBitSize(eEncodingSint,
- word_width),
- accessibility, unnamed_field_info->bit_size);
-
- layout_info.field_offsets.insert(std::make_pair(
- unnamed_bitfield_decl, unnamed_field_info->bit_offset));
- }
- }
+ if (detect_unnamed_bitfields)
+ AddUnnamedBitfieldToRecordTypeIfNeeded(layout_info, accessibility,
+ class_clang_type, last_field_info,
+ this_field_info);
last_field_info = this_field_info;
last_field_info.SetIsBitfield(true);
@@ -3764,6 +3733,44 @@ bool DWARFASTParserClang::ShouldCreateUnnamedBitfield(
return true;
}
+void DWARFASTParserClang::AddUnnamedBitfieldToRecordTypeIfNeeded(
+ ClangASTImporter::LayoutInfo &class_layout_info,
+ lldb::AccessType accessibility, const CompilerType &class_clang_type,
+ const FieldInfo &previous_field, const FieldInfo ¤t_field) {
+ // TODO: get this value from target
+ const uint64_t word_width = 32;
+ uint64_t last_field_end = previous_field.bit_offset + previous_field.bit_size;
+
+ if (!previous_field.IsBitfield()) {
+ // The last field was not a bit-field...
+ // but if it did take up the entire word then we need to extend
+ // last_field_end so the bit-field does not step into the last
+ // fields padding.
+ if (last_field_end != 0 && ((last_field_end % word_width) != 0))
+ last_field_end += word_width - (last_field_end % word_width);
+ }
+
+ // Nothing to be done.
+ if (!ShouldCreateUnnamedBitfield(previous_field, last_field_end,
+ current_field, class_layout_info))
+ return;
+
+ FieldInfo unnamed_field_info{.bit_size =
+ current_field.bit_offset - last_field_end,
+ .bit_offset = last_field_end,
+ .is_bitfield = false,
+ .is_artificial = false};
+
+ clang::FieldDecl *unnamed_bitfield_decl =
+ TypeSystemClang::AddFieldToRecordType(
+ class_clang_type, llvm::StringRef(),
+ m_ast.GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
+ accessibility, unnamed_field_info.bit_size);
+
+ class_layout_info.field_offsets.insert(
+ std::make_pair(unnamed_bitfield_decl, unnamed_field_info.bit_offset));
+}
+
void DWARFASTParserClang::ParseRustVariantPart(
DWARFDIE &die, const DWARFDIE &parent_die,
const CompilerType &class_clang_type,
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
index 2806fbbeb99d24..732d9eff4b9217 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -266,7 +266,7 @@ class DWARFASTParserClang : public lldb_private::plugin::dwarf::DWARFASTParser {
FieldInfo() = default;
void SetIsBitfield(bool flag) { is_bitfield = flag; }
- bool IsBitfield() { return is_bitfield; }
+ bool IsBitfield() const { return is_bitfield; }
void SetIsArtificial(bool flag) { is_artificial = flag; }
bool IsArtificial() const { return is_artificial; }
@@ -318,6 +318,12 @@ class DWARFASTParserClang : public lldb_private::plugin::dwarf::DWARFASTParser {
FieldInfo const &this_field_info,
lldb_private::ClangASTImporter::LayoutInfo const &layout_info) const;
+ void AddUnnamedBitfieldToRecordTypeIfNeeded(
+ lldb_private::ClangASTImporter::LayoutInfo &class_layout_info,
+ lldb::AccessType accessibility,
+ const lldb_private::CompilerType &class_clang_type,
+ const FieldInfo &previous_field, const FieldInfo ¤t_field);
+
/// Parses a DW_TAG_APPLE_property DIE and appends the parsed data to the
/// list of delayed Objective-C properties.
///
|
adrian-prantl
approved these changes
Sep 11, 2024
VitaNuo
pushed a commit
to VitaNuo/llvm-project
that referenced
this pull request
Sep 12, 2024
… into helper (llvm#108196) This logic will need adjusting soon for llvm#108155 This patch pulls out the logic for detecting/creating unnamed bitfields out of `ParseSingleMember` to make the latter (in my opinion) more readable. Otherwise we have a large number of similarly named variables in scope.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This logic will need adjusting soon for #108155
This patch pulls out the logic for detecting/creating unnamed bitfields out of
ParseSingleMember
to make the latter (in my opinion) more readable. Otherwise we have a large number of similarly named variables in scope.