Skip to content

Commit 5f7e6f9

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. (cherry picked from commit 162248c)
1 parent 6595eb7 commit 5f7e6f9

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
@@ -135,6 +135,11 @@ class PluginProperties : public Properties {
135135

136136
} // namespace
137137

138+
bool IsStructOrClassTag(llvm::dwarf::Tag Tag) {
139+
return Tag == llvm::dwarf::Tag::DW_TAG_class_type ||
140+
Tag == llvm::dwarf::Tag::DW_TAG_structure_type;
141+
}
142+
138143
static PluginProperties &GetGlobalPluginProperties() {
139144
static PluginProperties g_settings;
140145
return g_settings;
@@ -2888,29 +2893,18 @@ TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE(
28882893

28892894
m_index->GetCompleteObjCClass(
28902895
type_name, must_be_implementation, [&](DWARFDIE type_die) {
2891-
bool try_resolving_type = false;
2892-
28932896
// Don't try and resolve the DIE we are looking for with the DIE
28942897
// itself!
2895-
if (type_die != die) {
2896-
switch (type_die.Tag()) {
2897-
case DW_TAG_class_type:
2898-
case DW_TAG_structure_type:
2899-
try_resolving_type = true;
2900-
break;
2901-
default:
2902-
break;
2903-
}
2904-
}
2905-
if (!try_resolving_type)
2898+
if (type_die == die || !IsStructOrClassTag(type_die.Tag()))
29062899
return true;
29072900

29082901
if (must_be_implementation &&
2909-
type_die.Supports_DW_AT_APPLE_objc_complete_type())
2910-
try_resolving_type = type_die.GetAttributeValueAsUnsigned(
2902+
type_die.Supports_DW_AT_APPLE_objc_complete_type()) {
2903+
const bool try_resolving_type = type_die.GetAttributeValueAsUnsigned(
29112904
DW_AT_APPLE_objc_complete_type, 0);
2912-
if (!try_resolving_type)
2913-
return true;
2905+
if (!try_resolving_type)
2906+
return true;
2907+
}
29142908

29152909
Type *resolved_type = ResolveType(type_die, false, true);
29162910
if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
@@ -3069,36 +3063,12 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
30693063
if (type_system &&
30703064
!type_system->SupportsLanguage(GetLanguage(*type_die.GetCU())))
30713065
return true;
3072-
bool try_resolving_type = false;
30733066

3074-
// Don't try and resolve the DIE we are looking for with the DIE
3075-
// itself!
30763067
const dw_tag_t type_tag = type_die.Tag();
3077-
// Make sure the tags match
3078-
if (type_tag == tag) {
3079-
// The tags match, lets try resolving this type
3080-
try_resolving_type = true;
3081-
} else {
3082-
// The tags don't match, but we need to watch our for a forward
3083-
// declaration for a struct and ("struct foo") ends up being a
3084-
// class ("class foo { ... };") or vice versa.
3085-
switch (type_tag) {
3086-
case DW_TAG_class_type:
3087-
// We had a "class foo", see if we ended up with a "struct foo
3088-
// { ... };"
3089-
try_resolving_type = (tag == DW_TAG_structure_type);
3090-
break;
3091-
case DW_TAG_structure_type:
3092-
// We had a "struct foo", see if we ended up with a "class foo
3093-
// { ... };"
3094-
try_resolving_type = (tag == DW_TAG_class_type);
3095-
break;
3096-
default:
3097-
// Tags don't match, don't event try to resolve using this type
3098-
// whose name matches....
3099-
break;
3100-
}
3101-
}
3068+
// Resolve the type if both have the same tag or {class, struct} tags.
3069+
const bool try_resolving_type =
3070+
type_tag == tag ||
3071+
(IsStructOrClassTag(type_tag) && IsStructOrClassTag(tag));
31023072

31033073
if (!try_resolving_type) {
31043074
if (log) {

0 commit comments

Comments
 (0)