Skip to content

Commit f86770a

Browse files
committed
Reland "[lldb][DWARFASTParserClang] Make MemberAttributes const when parsing member DIEs (#71921)"
Changed the recently added `FindConstantOnVariableDefinition` to not rely on MemberAttributes being non-const. Original commit message: """ 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 563720c commit f86770a

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

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

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

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

29392931
// Handle static members, which are typically members without
29402932
// locations. However, GCC doesn't emit DW_AT_data_member_location
@@ -2949,13 +2941,13 @@ void DWARFASTParserClang::ParseSingleMember(
29492941
if (attrs.member_byte_offset == UINT32_MAX &&
29502942
attrs.data_bit_offset == UINT64_MAX && attrs.is_declaration) {
29512943
Type *var_type = die.ResolveTypeUID(attrs.encoding_form.Reference());
2952-
29532944
if (var_type) {
2954-
if (attrs.accessibility == eAccessNone)
2955-
attrs.accessibility = eAccessPublic;
2945+
const auto accessibility = attrs.accessibility == eAccessNone
2946+
? eAccessPublic
2947+
: attrs.accessibility;
29562948
CompilerType ct = var_type->GetForwardCompilerType();
29572949
clang::VarDecl *v = TypeSystemClang::AddVariableToRecordType(
2958-
class_clang_type, attrs.name, ct, attrs.accessibility);
2950+
class_clang_type, attrs.name, ct, accessibility);
29592951
if (!v) {
29602952
LLDB_LOG(log, "Failed to add variable to the record type");
29612953
return;
@@ -2966,20 +2958,20 @@ void DWARFASTParserClang::ParseSingleMember(
29662958
if (!ct.IsIntegerOrEnumerationType(unused))
29672959
return;
29682960

2961+
auto maybe_const_form_value = attrs.const_value_form;
2962+
29692963
// Newer versions of Clang don't emit the DW_AT_const_value
29702964
// on the declaration of an inline static data member. Instead
29712965
// it's attached to the definition DIE. If that's the case,
29722966
// try and fetch it.
2973-
if (!attrs.const_value_form) {
2974-
auto maybe_form_value = FindConstantOnVariableDefinition(die);
2975-
if (!maybe_form_value)
2967+
if (!maybe_const_form_value) {
2968+
maybe_const_form_value = FindConstantOnVariableDefinition(die);
2969+
if (!maybe_const_form_value)
29762970
return;
2977-
2978-
attrs.const_value_form = *maybe_form_value;
29792971
}
29802972

29812973
llvm::Expected<llvm::APInt> const_value_or_err =
2982-
ExtractIntFromFormValue(ct, *attrs.const_value_form);
2974+
ExtractIntFromFormValue(ct, *maybe_const_form_value);
29832975
if (!const_value_or_err) {
29842976
LLDB_LOG_ERROR(log, const_value_or_err.takeError(),
29852977
"Failed to add const value to variable {1}: {0}",
@@ -3011,8 +3003,9 @@ void DWARFASTParserClang::ParseSingleMember(
30113003
const uint64_t word_width = 32;
30123004
CompilerType member_clang_type = member_type->GetLayoutCompilerType();
30133005

3014-
if (attrs.accessibility == eAccessNone)
3015-
attrs.accessibility = default_accessibility;
3006+
const auto accessibility = attrs.accessibility == eAccessNone
3007+
? default_accessibility
3008+
: attrs.accessibility;
30163009

30173010
uint64_t field_bit_offset = (attrs.member_byte_offset == UINT32_MAX
30183011
? 0
@@ -3026,12 +3019,13 @@ void DWARFASTParserClang::ParseSingleMember(
30263019
if (attrs.data_bit_offset != UINT64_MAX) {
30273020
this_field_info.bit_offset = attrs.data_bit_offset;
30283021
} else {
3029-
if (!attrs.byte_size)
3030-
attrs.byte_size = member_type->GetByteSize(nullptr);
3022+
auto byte_size = attrs.byte_size;
3023+
if (!byte_size)
3024+
byte_size = member_type->GetByteSize(nullptr);
30313025

30323026
ObjectFile *objfile = die.GetDWARF()->GetObjectFile();
30333027
if (objfile->GetByteOrder() == eByteOrderLittle) {
3034-
this_field_info.bit_offset += attrs.byte_size.value_or(0) * 8;
3028+
this_field_info.bit_offset += byte_size.value_or(0) * 8;
30353029
this_field_info.bit_offset -= (attrs.bit_offset + attrs.bit_size);
30363030
} else {
30373031
this_field_info.bit_offset += attrs.bit_offset;
@@ -3070,7 +3064,7 @@ void DWARFASTParserClang::ParseSingleMember(
30703064
// unnamed bitfields if we have a new enough clang.
30713065
bool detect_unnamed_bitfields = true;
30723066

3073-
if (class_is_objc_object_or_interface)
3067+
if (TypeSystemClang::IsObjCObjectOrInterfaceType(class_clang_type))
30743068
detect_unnamed_bitfields =
30753069
die.GetCU()->Supports_unnamed_objc_bitfields();
30763070

@@ -3102,7 +3096,7 @@ void DWARFASTParserClang::ParseSingleMember(
31023096
class_clang_type, llvm::StringRef(),
31033097
m_ast.GetBuiltinTypeForEncodingAndBitSize(eEncodingSint,
31043098
word_width),
3105-
attrs.accessibility, unnamed_field_info->bit_size);
3099+
accessibility, unnamed_field_info->bit_size);
31063100

31073101
layout_info.field_offsets.insert(std::make_pair(
31083102
unnamed_bitfield_decl, unnamed_field_info->bit_offset));
@@ -3172,7 +3166,7 @@ void DWARFASTParserClang::ParseSingleMember(
31723166
TypeSystemClang::RequireCompleteType(member_clang_type);
31733167

31743168
clang::FieldDecl *field_decl = TypeSystemClang::AddFieldToRecordType(
3175-
class_clang_type, attrs.name, member_clang_type, attrs.accessibility,
3169+
class_clang_type, attrs.name, member_clang_type, accessibility,
31763170
attrs.bit_size);
31773171

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

0 commit comments

Comments
 (0)