@@ -2858,7 +2858,6 @@ void DWARFASTParserClang::ParseSingleMember(
2858
2858
}
2859
2859
2860
2860
const uint64_t character_width = 8 ;
2861
- const uint64_t word_width = 32 ;
2862
2861
CompilerType member_clang_type = member_type->GetLayoutCompilerType ();
2863
2862
2864
2863
const auto accessibility = attrs.accessibility == eAccessNone
@@ -2926,40 +2925,9 @@ void DWARFASTParserClang::ParseSingleMember(
2926
2925
detect_unnamed_bitfields =
2927
2926
die.GetCU ()->Supports_unnamed_objc_bitfields ();
2928
2927
2929
- if (detect_unnamed_bitfields) {
2930
- std::optional<FieldInfo> unnamed_field_info;
2931
- uint64_t last_field_end =
2932
- last_field_info.bit_offset + last_field_info.bit_size ;
2933
-
2934
- if (!last_field_info.IsBitfield ()) {
2935
- // The last field was not a bit-field...
2936
- // but if it did take up the entire word then we need to extend
2937
- // last_field_end so the bit-field does not step into the last
2938
- // fields padding.
2939
- if (last_field_end != 0 && ((last_field_end % word_width) != 0 ))
2940
- last_field_end += word_width - (last_field_end % word_width);
2941
- }
2942
-
2943
- if (ShouldCreateUnnamedBitfield (last_field_info, last_field_end,
2944
- this_field_info, layout_info)) {
2945
- unnamed_field_info = FieldInfo{};
2946
- unnamed_field_info->bit_size =
2947
- this_field_info.bit_offset - last_field_end;
2948
- unnamed_field_info->bit_offset = last_field_end;
2949
- }
2950
-
2951
- if (unnamed_field_info) {
2952
- clang::FieldDecl *unnamed_bitfield_decl =
2953
- TypeSystemClang::AddFieldToRecordType (
2954
- class_clang_type, llvm::StringRef (),
2955
- m_ast.GetBuiltinTypeForEncodingAndBitSize (eEncodingSint,
2956
- word_width),
2957
- accessibility, unnamed_field_info->bit_size );
2958
-
2959
- layout_info.field_offsets .insert (std::make_pair (
2960
- unnamed_bitfield_decl, unnamed_field_info->bit_offset ));
2961
- }
2962
- }
2928
+ if (detect_unnamed_bitfields)
2929
+ AddUnnamedBitfieldToRecordTypeIfNeeded (layout_info, class_clang_type,
2930
+ last_field_info, this_field_info);
2963
2931
2964
2932
last_field_info = this_field_info;
2965
2933
last_field_info.SetIsBitfield (true );
@@ -3764,6 +3732,43 @@ bool DWARFASTParserClang::ShouldCreateUnnamedBitfield(
3764
3732
return true ;
3765
3733
}
3766
3734
3735
+ void DWARFASTParserClang::AddUnnamedBitfieldToRecordTypeIfNeeded (
3736
+ ClangASTImporter::LayoutInfo &class_layout_info,
3737
+ const CompilerType &class_clang_type, const FieldInfo &previous_field,
3738
+ const FieldInfo ¤t_field) {
3739
+ // TODO: get this value from target
3740
+ const uint64_t word_width = 32 ;
3741
+ uint64_t last_field_end = previous_field.bit_offset + previous_field.bit_size ;
3742
+
3743
+ if (!previous_field.IsBitfield ()) {
3744
+ // The last field was not a bit-field...
3745
+ // but if it did take up the entire word then we need to extend
3746
+ // last_field_end so the bit-field does not step into the last
3747
+ // fields padding.
3748
+ if (last_field_end != 0 && ((last_field_end % word_width) != 0 ))
3749
+ last_field_end += word_width - (last_field_end % word_width);
3750
+ }
3751
+
3752
+ // Nothing to be done.
3753
+ if (!ShouldCreateUnnamedBitfield (previous_field, last_field_end,
3754
+ current_field, class_layout_info))
3755
+ return ;
3756
+
3757
+ // Place the unnamed bitfield into the gap between the previous field's end
3758
+ // and the current field's start.
3759
+ const uint64_t unnamed_bit_size = current_field.bit_offset - last_field_end;
3760
+ const uint64_t unnamed_bit_offset = last_field_end;
3761
+
3762
+ clang::FieldDecl *unnamed_bitfield_decl =
3763
+ TypeSystemClang::AddFieldToRecordType (
3764
+ class_clang_type, llvm::StringRef (),
3765
+ m_ast.GetBuiltinTypeForEncodingAndBitSize (eEncodingSint, word_width),
3766
+ lldb::AccessType::eAccessPublic, unnamed_bit_size);
3767
+
3768
+ class_layout_info.field_offsets .insert (
3769
+ std::make_pair (unnamed_bitfield_decl, unnamed_bit_offset));
3770
+ }
3771
+
3767
3772
void DWARFASTParserClang::ParseRustVariantPart (
3768
3773
DWARFDIE &die, const DWARFDIE &parent_die,
3769
3774
const CompilerType &class_clang_type,
0 commit comments