Skip to content

Commit 576f7cc

Browse files
authored
[lldb][DWARFASTParserClang] Make MemberAttributes const when parsing member DIEs (#71921)
This patch removes the Objective-C accessibility workaround added in 5a477cf (rdar://8492646). This allows us to make the local `MemberAttributes` variable immutable, which is useful for some other work around this function I was planning on doing. We don't need the workaround anymore since compiler-support for giving debuggers access to private ivars was done couple of years later in d6cb4a8 (rdar://10997647). **Testing** * Test-suite runs cleanly
1 parent 15c8085 commit 576f7cc

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,15 +2925,7 @@ void DWARFASTParserClang::ParseSingleMember(
29252925
const uint64_t parent_bit_size =
29262926
parent_byte_size == UINT64_MAX ? UINT64_MAX : parent_byte_size * 8;
29272927

2928-
// FIXME: Remove the workarounds below and make this const.
2929-
MemberAttributes attrs(die, parent_die, module_sp);
2930-
2931-
const bool class_is_objc_object_or_interface =
2932-
TypeSystemClang::IsObjCObjectOrInterfaceType(class_clang_type);
2933-
2934-
// FIXME: Make Clang ignore Objective-C accessibility for expressions
2935-
if (class_is_objc_object_or_interface)
2936-
attrs.accessibility = eAccessNone;
2928+
const MemberAttributes attrs(die, parent_die, module_sp);
29372929

29382930
// Handle static members, which are typically members without
29392931
// locations. However, GCC doesn't emit DW_AT_data_member_location
@@ -2948,13 +2940,13 @@ void DWARFASTParserClang::ParseSingleMember(
29482940
if (attrs.member_byte_offset == UINT32_MAX &&
29492941
attrs.data_bit_offset == UINT64_MAX && attrs.is_declaration) {
29502942
Type *var_type = die.ResolveTypeUID(attrs.encoding_form.Reference());
2951-
29522943
if (var_type) {
2953-
if (attrs.accessibility == eAccessNone)
2954-
attrs.accessibility = eAccessPublic;
2944+
const auto accessibility = attrs.accessibility == eAccessNone
2945+
? eAccessPublic
2946+
: attrs.accessibility;
29552947
CompilerType ct = var_type->GetForwardCompilerType();
29562948
clang::VarDecl *v = TypeSystemClang::AddVariableToRecordType(
2957-
class_clang_type, attrs.name, ct, attrs.accessibility);
2949+
class_clang_type, attrs.name, ct, accessibility);
29582950
if (!v) {
29592951
LLDB_LOG(log, "Failed to add variable to the record type");
29602952
return;
@@ -3010,8 +3002,9 @@ void DWARFASTParserClang::ParseSingleMember(
30103002
const uint64_t word_width = 32;
30113003
CompilerType member_clang_type = member_type->GetLayoutCompilerType();
30123004

3013-
if (attrs.accessibility == eAccessNone)
3014-
attrs.accessibility = default_accessibility;
3005+
const auto accessibility = attrs.accessibility == eAccessNone
3006+
? default_accessibility
3007+
: attrs.accessibility;
30153008

30163009
uint64_t field_bit_offset = (attrs.member_byte_offset == UINT32_MAX
30173010
? 0
@@ -3025,12 +3018,13 @@ void DWARFASTParserClang::ParseSingleMember(
30253018
if (attrs.data_bit_offset != UINT64_MAX) {
30263019
this_field_info.bit_offset = attrs.data_bit_offset;
30273020
} else {
3028-
if (!attrs.byte_size)
3029-
attrs.byte_size = member_type->GetByteSize(nullptr);
3021+
auto byte_size = attrs.byte_size;
3022+
if (!byte_size)
3023+
byte_size = member_type->GetByteSize(nullptr);
30303024

30313025
ObjectFile *objfile = die.GetDWARF()->GetObjectFile();
30323026
if (objfile->GetByteOrder() == eByteOrderLittle) {
3033-
this_field_info.bit_offset += attrs.byte_size.value_or(0) * 8;
3027+
this_field_info.bit_offset += byte_size.value_or(0) * 8;
30343028
this_field_info.bit_offset -= (attrs.bit_offset + attrs.bit_size);
30353029
} else {
30363030
this_field_info.bit_offset += attrs.bit_offset;
@@ -3069,7 +3063,7 @@ void DWARFASTParserClang::ParseSingleMember(
30693063
// unnamed bitfields if we have a new enough clang.
30703064
bool detect_unnamed_bitfields = true;
30713065

3072-
if (class_is_objc_object_or_interface)
3066+
if (TypeSystemClang::IsObjCObjectOrInterfaceType(class_clang_type))
30733067
detect_unnamed_bitfields =
30743068
die.GetCU()->Supports_unnamed_objc_bitfields();
30753069

@@ -3101,7 +3095,7 @@ void DWARFASTParserClang::ParseSingleMember(
31013095
class_clang_type, llvm::StringRef(),
31023096
m_ast.GetBuiltinTypeForEncodingAndBitSize(eEncodingSint,
31033097
word_width),
3104-
attrs.accessibility, unnamed_field_info->bit_size);
3098+
accessibility, unnamed_field_info->bit_size);
31053099

31063100
layout_info.field_offsets.insert(std::make_pair(
31073101
unnamed_bitfield_decl, unnamed_field_info->bit_offset));
@@ -3171,7 +3165,7 @@ void DWARFASTParserClang::ParseSingleMember(
31713165
TypeSystemClang::RequireCompleteType(member_clang_type);
31723166

31733167
clang::FieldDecl *field_decl = TypeSystemClang::AddFieldToRecordType(
3174-
class_clang_type, attrs.name, member_clang_type, attrs.accessibility,
3168+
class_clang_type, attrs.name, member_clang_type, accessibility,
31753169
attrs.bit_size);
31763170

31773171
m_ast.SetMetadataAsUserID(field_decl, die.GetID());

0 commit comments

Comments
 (0)