diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp --- a/lldb/source/Core/Mangled.cpp +++ b/lldb/source/Core/Mangled.cpp @@ -164,7 +164,7 @@ return demangled_cstr; } -static char *GetDLangDemangledStr(const char *M) { +static char *GetDLangDemangledStr(std::string_view M) { char *demangled_cstr = llvm::dlangDemangle(M); if (Log *log = GetLog(LLDBLog::Demangle)) { @@ -263,7 +263,7 @@ demangled_name = GetRustV0DemangledStr(m_mangled); break; case eManglingSchemeD: - demangled_name = GetDLangDemangledStr(mangled_name); + demangled_name = GetDLangDemangledStr(m_mangled); break; case eManglingSchemeNone: llvm_unreachable("eManglingSchemeNone was handled already"); diff --git a/llvm/include/llvm/Demangle/Demangle.h b/llvm/include/llvm/Demangle/Demangle.h --- a/llvm/include/llvm/Demangle/Demangle.h +++ b/llvm/include/llvm/Demangle/Demangle.h @@ -58,7 +58,7 @@ char *rustDemangle(std::string_view MangledName); // Demangles a D mangled symbol. -char *dlangDemangle(const char *MangledName); +char *dlangDemangle(std::string_view MangledName); /// Attempt to demangle a string using different demangling schemes. /// The function uses heuristics to determine which demangling scheme to use. diff --git a/llvm/lib/Demangle/DLangDemangle.cpp b/llvm/lib/Demangle/DLangDemangle.cpp --- a/llvm/lib/Demangle/DLangDemangle.cpp +++ b/llvm/lib/Demangle/DLangDemangle.cpp @@ -14,6 +14,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Demangle/Demangle.h" +#include "llvm/Demangle/StringViewExtras.h" #include "llvm/Demangle/Utility.h" #include @@ -22,6 +23,7 @@ using namespace llvm; using llvm::itanium_demangle::OutputBuffer; +using llvm::itanium_demangle::starts_with; namespace { @@ -541,20 +543,20 @@ return parseMangle(Demangled, this->Str); } -char *llvm::dlangDemangle(const char *MangledName) { - if (MangledName == nullptr || strncmp(MangledName, "_D", 2) != 0) +char *llvm::dlangDemangle(std::string_view MangledName) { + if (MangledName.empty() || !starts_with(MangledName, "_D")) return nullptr; OutputBuffer Demangled; - if (strcmp(MangledName, "_Dmain") == 0) { + if (MangledName == "_Dmain") { Demangled << "D main"; } else { - Demangler D = Demangler(MangledName); - MangledName = D.parseMangle(&Demangled); + Demangler D(MangledName.data()); + const char *M = D.parseMangle(&Demangled); // Check that the entire symbol was successfully demangled. - if (MangledName == nullptr || *MangledName != '\0') { + if (M == nullptr || *M != '\0') { std::free(Demangled.getBuffer()); return nullptr; } diff --git a/llvm/lib/Demangle/Demangle.cpp b/llvm/lib/Demangle/Demangle.cpp --- a/llvm/lib/Demangle/Demangle.cpp +++ b/llvm/lib/Demangle/Demangle.cpp @@ -53,7 +53,7 @@ else if (isRustEncoding(MangledName.data())) Demangled = rustDemangle(MangledName); else if (isDLangEncoding(MangledName.data())) - Demangled = dlangDemangle(MangledName.data()); + Demangled = dlangDemangle(MangledName); if (!Demangled) return false; diff --git a/llvm/tools/llvm-dlang-demangle-fuzzer/llvm-dlang-demangle-fuzzer.cpp b/llvm/tools/llvm-dlang-demangle-fuzzer/llvm-dlang-demangle-fuzzer.cpp --- a/llvm/tools/llvm-dlang-demangle-fuzzer/llvm-dlang-demangle-fuzzer.cpp +++ b/llvm/tools/llvm-dlang-demangle-fuzzer/llvm-dlang-demangle-fuzzer.cpp @@ -13,7 +13,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { std::string NullTerminatedString((const char *)Data, Size); - char *Demangled = llvm::dlangDemangle(NullTerminatedString.c_str()); + char *Demangled = llvm::dlangDemangle(NullTerminatedString); std::free(Demangled); return 0; } diff --git a/llvm/unittests/Demangle/DLangDemangleTest.cpp b/llvm/unittests/Demangle/DLangDemangleTest.cpp --- a/llvm/unittests/Demangle/DLangDemangleTest.cpp +++ b/llvm/unittests/Demangle/DLangDemangleTest.cpp @@ -11,10 +11,11 @@ #include "gtest/gtest.h" #include +#include #include struct DLangDemangleTestFixture - : public testing::TestWithParam> { + : public testing::TestWithParam> { char *Demangled; void SetUp() override { Demangled = llvm::dlangDemangle(GetParam().first); } @@ -29,9 +30,8 @@ INSTANTIATE_TEST_SUITE_P( DLangDemangleTest, DLangDemangleTestFixture, testing::Values( - std::make_pair("_Dmain", "D main"), std::make_pair(nullptr, nullptr), - std::make_pair("_Z", nullptr), std::make_pair("_DDD", nullptr), - std::make_pair("_D88", nullptr), + std::make_pair("_Dmain", "D main"), std::make_pair("_Z", nullptr), + std::make_pair("_DDD", nullptr), std::make_pair("_D88", nullptr), std::make_pair("_D8demangleZ", "demangle"), std::make_pair("_D8demangle4testZ", "demangle.test"), std::make_pair("_D8demangle4test5test2Z", "demangle.test.test2"),