@@ -2839,10 +2839,9 @@ void DWARFASTParserClang::ParseSingleMember(
2839
2839
die.GetCU ()->Supports_unnamed_objc_bitfields ();
2840
2840
2841
2841
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 ;
2846
2845
2847
2846
if (!last_field_info.IsBitfield ()) {
2848
2847
// The last field was not a bit-field...
@@ -2853,20 +2852,8 @@ void DWARFASTParserClang::ParseSingleMember(
2853
2852
last_field_end += word_width - (last_field_end % word_width);
2854
2853
}
2855
2854
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)) {
2870
2857
unnamed_field_info = FieldInfo{};
2871
2858
unnamed_field_info->bit_size =
2872
2859
this_field_info.bit_offset - last_field_end;
@@ -2907,8 +2894,10 @@ void DWARFASTParserClang::ParseSingleMember(
2907
2894
// artificial member with (unnamed bitfield) padding.
2908
2895
// FIXME: This check should verify that this is indeed an artificial member
2909
2896
// we are supposed to ignore.
2910
- if (attrs.is_artificial )
2897
+ if (attrs.is_artificial ) {
2898
+ last_field_info.SetIsArtificial (true );
2911
2899
return ;
2900
+ }
2912
2901
2913
2902
if (!member_clang_type.IsCompleteType ())
2914
2903
member_clang_type.GetCompleteType ();
@@ -3660,3 +3649,35 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes(
3660
3649
3661
3650
return !failures.empty ();
3662
3651
}
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