@@ -3024,7 +3024,6 @@ void DWARFASTParserClang::ParseSingleMember(
30243024 }
30253025
30263026 const uint64_t character_width = 8 ;
3027- const uint64_t word_width = 32 ;
30283027 CompilerType member_clang_type = member_type->GetLayoutCompilerType ();
30293028
30303029 const auto accessibility = attrs.accessibility == eAccessNone
@@ -3092,40 +3091,9 @@ void DWARFASTParserClang::ParseSingleMember(
30923091 detect_unnamed_bitfields =
30933092 die.GetCU ()->Supports_unnamed_objc_bitfields ();
30943093
3095- if (detect_unnamed_bitfields) {
3096- std::optional<FieldInfo> unnamed_field_info;
3097- uint64_t last_field_end =
3098- last_field_info.bit_offset + last_field_info.bit_size ;
3099-
3100- if (!last_field_info.IsBitfield ()) {
3101- // The last field was not a bit-field...
3102- // but if it did take up the entire word then we need to extend
3103- // last_field_end so the bit-field does not step into the last
3104- // fields padding.
3105- if (last_field_end != 0 && ((last_field_end % word_width) != 0 ))
3106- last_field_end += word_width - (last_field_end % word_width);
3107- }
3108-
3109- if (ShouldCreateUnnamedBitfield (last_field_info, last_field_end,
3110- this_field_info, layout_info)) {
3111- unnamed_field_info = FieldInfo{};
3112- unnamed_field_info->bit_size =
3113- this_field_info.bit_offset - last_field_end;
3114- unnamed_field_info->bit_offset = last_field_end;
3115- }
3116-
3117- if (unnamed_field_info) {
3118- clang::FieldDecl *unnamed_bitfield_decl =
3119- TypeSystemClang::AddFieldToRecordType (
3120- class_clang_type, llvm::StringRef (),
3121- m_ast.GetBuiltinTypeForEncodingAndBitSize (eEncodingSint,
3122- word_width),
3123- accessibility, unnamed_field_info->bit_size );
3124-
3125- layout_info.field_offsets .insert (std::make_pair (
3126- unnamed_bitfield_decl, unnamed_field_info->bit_offset ));
3127- }
3128- }
3094+ if (detect_unnamed_bitfields)
3095+ AddUnnamedBitfieldToRecordTypeIfNeeded (layout_info, class_clang_type,
3096+ last_field_info, this_field_info);
31293097
31303098 last_field_info = this_field_info;
31313099 last_field_info.SetIsBitfield (true );
@@ -3937,6 +3905,43 @@ bool DWARFASTParserClang::ShouldCreateUnnamedBitfield(
39373905 return true ;
39383906}
39393907
3908+ void DWARFASTParserClang::AddUnnamedBitfieldToRecordTypeIfNeeded (
3909+ ClangASTImporter::LayoutInfo &class_layout_info,
3910+ const CompilerType &class_clang_type, const FieldInfo &previous_field,
3911+ const FieldInfo ¤t_field) {
3912+ // TODO: get this value from target
3913+ const uint64_t word_width = 32 ;
3914+ uint64_t last_field_end = previous_field.bit_offset + previous_field.bit_size ;
3915+
3916+ if (!previous_field.IsBitfield ()) {
3917+ // The last field was not a bit-field...
3918+ // but if it did take up the entire word then we need to extend
3919+ // last_field_end so the bit-field does not step into the last
3920+ // fields padding.
3921+ if (last_field_end != 0 && ((last_field_end % word_width) != 0 ))
3922+ last_field_end += word_width - (last_field_end % word_width);
3923+ }
3924+
3925+ // Nothing to be done.
3926+ if (!ShouldCreateUnnamedBitfield (previous_field, last_field_end,
3927+ current_field, class_layout_info))
3928+ return ;
3929+
3930+ // Place the unnamed bitfield into the gap between the previous field's end
3931+ // and the current field's start.
3932+ const uint64_t unnamed_bit_size = current_field.bit_offset - last_field_end;
3933+ const uint64_t unnamed_bit_offset = last_field_end;
3934+
3935+ clang::FieldDecl *unnamed_bitfield_decl =
3936+ TypeSystemClang::AddFieldToRecordType (
3937+ class_clang_type, llvm::StringRef (),
3938+ m_ast.GetBuiltinTypeForEncodingAndBitSize (eEncodingSint, word_width),
3939+ lldb::AccessType::eAccessPublic, unnamed_bit_size);
3940+
3941+ class_layout_info.field_offsets .insert (
3942+ std::make_pair (unnamed_bitfield_decl, unnamed_bit_offset));
3943+ }
3944+
39403945void DWARFASTParserClang::ParseRustVariantPart (
39413946 DWARFDIE &die, const DWARFDIE &parent_die, CompilerType &class_clang_type,
39423947 const lldb::AccessType default_accesibility,
0 commit comments