Skip to content

[lldb][Mangled] Use early-return style in GetDemangledName #130622

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 1 commit into from
Mar 11, 2025
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
89 changes: 45 additions & 44 deletions lldb/source/Core/Mangled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,50 +270,51 @@ bool Mangled::GetRichManglingInfo(RichManglingContext &context,
// name. The result is cached and will be kept until a new string value is
// supplied to this object, or until the end of the object's lifetime.
ConstString Mangled::GetDemangledName() const {
// Check to make sure we have a valid mangled name and that we haven't
// already decoded our mangled name.
if (m_mangled && m_demangled.IsNull()) {
// Don't bother running anything that isn't mangled
const char *mangled_name = m_mangled.GetCString();
ManglingScheme mangling_scheme =
GetManglingScheme(m_mangled.GetStringRef());
if (mangling_scheme != eManglingSchemeNone &&
!m_mangled.GetMangledCounterpart(m_demangled)) {
// We didn't already mangle this name, demangle it and if all goes well
// add it to our map.
char *demangled_name = nullptr;
switch (mangling_scheme) {
case eManglingSchemeMSVC:
demangled_name = GetMSVCDemangledStr(mangled_name);
break;
case eManglingSchemeItanium: {
demangled_name = GetItaniumDemangledStr(mangled_name);
break;
}
case eManglingSchemeRustV0:
demangled_name = GetRustV0DemangledStr(m_mangled);
break;
case eManglingSchemeD:
demangled_name = GetDLangDemangledStr(m_mangled);
break;
case eManglingSchemeSwift:
// Demangling a swift name requires the swift compiler. This is
// explicitly unsupported on llvm.org.
break;
case eManglingSchemeNone:
llvm_unreachable("eManglingSchemeNone was handled already");
}
if (demangled_name) {
m_demangled.SetStringWithMangledCounterpart(
llvm::StringRef(demangled_name), m_mangled);
free(demangled_name);
}
}
if (m_demangled.IsNull()) {
// Set the demangled string to the empty string to indicate we tried to
// parse it once and failed.
m_demangled.SetCString("");
}
if (!m_mangled)
return m_demangled;

// Re-use previously demangled names.
if (!m_demangled.IsNull())
return m_demangled;

if (m_mangled.GetMangledCounterpart(m_demangled) && !m_demangled.IsNull())
return m_demangled;

// We didn't already mangle this name, demangle it and if all goes well
// add it to our map.
char *demangled_name = nullptr;
switch (GetManglingScheme(m_mangled.GetStringRef())) {
case eManglingSchemeMSVC:
demangled_name = GetMSVCDemangledStr(m_mangled);
break;
case eManglingSchemeItanium: {
demangled_name = GetItaniumDemangledStr(m_mangled.GetCString());
break;
}
case eManglingSchemeRustV0:
demangled_name = GetRustV0DemangledStr(m_mangled);
break;
case eManglingSchemeD:
demangled_name = GetDLangDemangledStr(m_mangled);
break;
case eManglingSchemeSwift:
// Demangling a swift name requires the swift compiler. This is
// explicitly unsupported on llvm.org.
break;
case eManglingSchemeNone:
// Don't bother demangling anything that isn't mangled.
break;
}

if (demangled_name) {
m_demangled.SetStringWithMangledCounterpart(demangled_name, m_mangled);
free(demangled_name);
}

if (m_demangled.IsNull()) {
// Set the demangled string to the empty string to indicate we tried to
// parse it once and failed.
m_demangled.SetCString("");
}

return m_demangled;
Expand Down