@@ -2839,10 +2839,9 @@ void DWARFASTParserClang::ParseSingleMember(
28392839 die.GetCU ()->Supports_unnamed_objc_bitfields ();
28402840
28412841 if (detect_unnamed_bitfields) {
2842- llvm::Optional<FieldInfo> unnamed_field_info;
2843- uint64_t last_field_end = 0 ;
2844-
2845- last_field_end = last_field_info.bit_offset + last_field_info.bit_size ;
2842+ std::optional<FieldInfo> unnamed_field_info;
2843+ uint64_t last_field_end =
2844+ last_field_info.bit_offset + last_field_info.bit_size ;
28462845
28472846 if (!last_field_info.IsBitfield ()) {
28482847 // The last field was not a bit-field...
@@ -2853,20 +2852,8 @@ void DWARFASTParserClang::ParseSingleMember(
28532852 last_field_end += word_width - (last_field_end % word_width);
28542853 }
28552854
2856- // If we have a gap between the last_field_end and the current
2857- // field we have an unnamed bit-field.
2858- // If we have a base class, we assume there is no unnamed
2859- // bit-field if this is the first field since the gap can be
2860- // attributed to the members from the base class. This assumption
2861- // is not correct if the first field of the derived class is
2862- // indeed an unnamed bit-field. We currently do not have the
2863- // machinary to track the offset of the last field of classes we
2864- // have seen before, so we are not handling this case.
2865- if (this_field_info.bit_offset != last_field_end &&
2866- this_field_info.bit_offset > last_field_end &&
2867- !(last_field_info.bit_offset == 0 &&
2868- last_field_info.bit_size == 0 &&
2869- layout_info.base_offsets .size () != 0 )) {
2855+ if (ShouldCreateUnnamedBitfield (last_field_info, last_field_end,
2856+ this_field_info, layout_info)) {
28702857 unnamed_field_info = FieldInfo{};
28712858 unnamed_field_info->bit_size =
28722859 this_field_info.bit_offset - last_field_end;
@@ -2907,8 +2894,10 @@ void DWARFASTParserClang::ParseSingleMember(
29072894 // artificial member with (unnamed bitfield) padding.
29082895 // FIXME: This check should verify that this is indeed an artificial member
29092896 // we are supposed to ignore.
2910- if (attrs.is_artificial )
2897+ if (attrs.is_artificial ) {
2898+ last_field_info.SetIsArtificial (true );
29112899 return ;
2900+ }
29122901
29132902 if (!member_clang_type.IsCompleteType ())
29142903 member_clang_type.GetCompleteType ();
@@ -3660,3 +3649,35 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes(
36603649
36613650 return !failures.empty ();
36623651}
3652+
3653+ bool DWARFASTParserClang::ShouldCreateUnnamedBitfield (
3654+ FieldInfo const &last_field_info, uint64_t last_field_end,
3655+ FieldInfo const &this_field_info,
3656+ lldb_private::ClangASTImporter::LayoutInfo const &layout_info) const {
3657+ // If we have a gap between the last_field_end and the current
3658+ // field we have an unnamed bit-field.
3659+ if (this_field_info.bit_offset <= last_field_end)
3660+ return false ;
3661+
3662+ // If we have a base class, we assume there is no unnamed
3663+ // bit-field if either of the following is true:
3664+ // (a) this is the first field since the gap can be
3665+ // attributed to the members from the base class.
3666+ // FIXME: This assumption is not correct if the first field of
3667+ // the derived class is indeed an unnamed bit-field. We currently
3668+ // do not have the machinary to track the offset of the last field
3669+ // of classes we have seen before, so we are not handling this case.
3670+ // (b) Or, the first member of the derived class was a vtable pointer.
3671+ // In this case we don't want to create an unnamed bitfield either
3672+ // since those will be inserted by clang later.
3673+ const bool have_base = layout_info.base_offsets .size () != 0 ;
3674+ const bool this_is_first_field =
3675+ last_field_info.bit_offset == 0 && last_field_info.bit_size == 0 ;
3676+ const bool first_field_is_vptr =
3677+ last_field_info.bit_offset == 0 && last_field_info.IsArtificial ();
3678+
3679+ if (have_base && (this_is_first_field || first_field_is_vptr))
3680+ return false ;
3681+
3682+ return true ;
3683+ }
0 commit comments