Skip to content

Commit 162248c

Browse files
[SymbolFileDWARF][NFC] Remove duplicated code checking for type tags (llvm#74773)
There was duplicated (and complex) code querying whether tags were type-like tags (i.e. class or struct); this has been factored out into a helper function. There was also a comment about not comparing identical DIEs without ever performing that check; this comment has been removed. It was likely a result of copy paste from another function in this same file which actually does that check.
1 parent dd32d26 commit 162248c

File tree

1 file changed

+15
-45
lines changed

1 file changed

+15
-45
lines changed

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

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ class PluginProperties : public Properties {
132132

133133
} // namespace
134134

135+
bool IsStructOrClassTag(llvm::dwarf::Tag Tag) {
136+
return Tag == llvm::dwarf::Tag::DW_TAG_class_type ||
137+
Tag == llvm::dwarf::Tag::DW_TAG_structure_type;
138+
}
139+
135140
static PluginProperties &GetGlobalPluginProperties() {
136141
static PluginProperties g_settings;
137142
return g_settings;
@@ -2947,29 +2952,18 @@ TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE(
29472952

29482953
m_index->GetCompleteObjCClass(
29492954
type_name, must_be_implementation, [&](DWARFDIE type_die) {
2950-
bool try_resolving_type = false;
2951-
29522955
// Don't try and resolve the DIE we are looking for with the DIE
29532956
// itself!
2954-
if (type_die != die) {
2955-
switch (type_die.Tag()) {
2956-
case DW_TAG_class_type:
2957-
case DW_TAG_structure_type:
2958-
try_resolving_type = true;
2959-
break;
2960-
default:
2961-
break;
2962-
}
2963-
}
2964-
if (!try_resolving_type)
2957+
if (type_die == die || !IsStructOrClassTag(type_die.Tag()))
29652958
return true;
29662959

29672960
if (must_be_implementation &&
2968-
type_die.Supports_DW_AT_APPLE_objc_complete_type())
2969-
try_resolving_type = type_die.GetAttributeValueAsUnsigned(
2961+
type_die.Supports_DW_AT_APPLE_objc_complete_type()) {
2962+
const bool try_resolving_type = type_die.GetAttributeValueAsUnsigned(
29702963
DW_AT_APPLE_objc_complete_type, 0);
2971-
if (!try_resolving_type)
2972-
return true;
2964+
if (!try_resolving_type)
2965+
return true;
2966+
}
29732967

29742968
Type *resolved_type = ResolveType(type_die, false, true);
29752969
if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
@@ -3128,36 +3122,12 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
31283122
if (type_system &&
31293123
!type_system->SupportsLanguage(GetLanguage(*type_die.GetCU())))
31303124
return true;
3131-
bool try_resolving_type = false;
31323125

3133-
// Don't try and resolve the DIE we are looking for with the DIE
3134-
// itself!
31353126
const dw_tag_t type_tag = type_die.Tag();
3136-
// Make sure the tags match
3137-
if (type_tag == tag) {
3138-
// The tags match, lets try resolving this type
3139-
try_resolving_type = true;
3140-
} else {
3141-
// The tags don't match, but we need to watch our for a forward
3142-
// declaration for a struct and ("struct foo") ends up being a
3143-
// class ("class foo { ... };") or vice versa.
3144-
switch (type_tag) {
3145-
case DW_TAG_class_type:
3146-
// We had a "class foo", see if we ended up with a "struct foo
3147-
// { ... };"
3148-
try_resolving_type = (tag == DW_TAG_structure_type);
3149-
break;
3150-
case DW_TAG_structure_type:
3151-
// We had a "struct foo", see if we ended up with a "class foo
3152-
// { ... };"
3153-
try_resolving_type = (tag == DW_TAG_class_type);
3154-
break;
3155-
default:
3156-
// Tags don't match, don't event try to resolve using this type
3157-
// whose name matches....
3158-
break;
3159-
}
3160-
}
3127+
// Resolve the type if both have the same tag or {class, struct} tags.
3128+
const bool try_resolving_type =
3129+
type_tag == tag ||
3130+
(IsStructOrClassTag(type_tag) && IsStructOrClassTag(tag));
31613131

31623132
if (!try_resolving_type) {
31633133
if (log) {

0 commit comments

Comments
 (0)