Skip to content

[SymbolFileDWARF][NFC] Remove duplicated code checking for type tags #74773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 15 additions & 45 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ class PluginProperties : public Properties {

} // namespace

bool IsStructOrClassTag(llvm::dwarf::Tag Tag) {
return Tag == llvm::dwarf::Tag::DW_TAG_class_type ||
Tag == llvm::dwarf::Tag::DW_TAG_structure_type;
}

static PluginProperties &GetGlobalPluginProperties() {
static PluginProperties g_settings;
return g_settings;
Expand Down Expand Up @@ -2947,29 +2952,18 @@ TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE(

m_index->GetCompleteObjCClass(
type_name, must_be_implementation, [&](DWARFDIE type_die) {
bool try_resolving_type = false;

// Don't try and resolve the DIE we are looking for with the DIE
// itself!
if (type_die != die) {
switch (type_die.Tag()) {
case DW_TAG_class_type:
case DW_TAG_structure_type:
try_resolving_type = true;
break;
default:
break;
}
}
if (!try_resolving_type)
if (type_die == die || !IsStructOrClassTag(type_die.Tag()))
return true;

if (must_be_implementation &&
type_die.Supports_DW_AT_APPLE_objc_complete_type())
try_resolving_type = type_die.GetAttributeValueAsUnsigned(
type_die.Supports_DW_AT_APPLE_objc_complete_type()) {
const bool try_resolving_type = type_die.GetAttributeValueAsUnsigned(
DW_AT_APPLE_objc_complete_type, 0);
if (!try_resolving_type)
return true;
if (!try_resolving_type)
return true;
}

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

// Don't try and resolve the DIE we are looking for with the DIE
// itself!
const dw_tag_t type_tag = type_die.Tag();
// Make sure the tags match
if (type_tag == tag) {
// The tags match, lets try resolving this type
try_resolving_type = true;
} else {
// The tags don't match, but we need to watch our for a forward
// declaration for a struct and ("struct foo") ends up being a
// class ("class foo { ... };") or vice versa.
switch (type_tag) {
case DW_TAG_class_type:
// We had a "class foo", see if we ended up with a "struct foo
// { ... };"
try_resolving_type = (tag == DW_TAG_structure_type);
break;
case DW_TAG_structure_type:
// We had a "struct foo", see if we ended up with a "class foo
// { ... };"
try_resolving_type = (tag == DW_TAG_class_type);
break;
default:
// Tags don't match, don't event try to resolve using this type
// whose name matches....
break;
}
}
// Resolve the type if both have the same tag or {class, struct} tags.
const bool try_resolving_type =
type_tag == tag ||
(IsStructOrClassTag(type_tag) && IsStructOrClassTag(tag));

if (!try_resolving_type) {
if (log) {
Expand Down