This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGf5371eb3d3ae: [Damangle] convert dlangDemangle to use std::string_view (authored by nickdesaulniers).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151003/new/ https://reviews.llvm.org/D151003 Files: lldb/source/Core/Mangled.cpp llvm/include/llvm/Demangle/Demangle.h llvm/lib/Demangle/DLangDemangle.cpp llvm/lib/Demangle/Demangle.cpp llvm/tools/llvm-dlang-demangle-fuzzer/llvm-dlang-demangle-fuzzer.cpp llvm/unittests/Demangle/DLangDemangleTest.cpp
Index: llvm/unittests/Demangle/DLangDemangleTest.cpp =================================================================== --- llvm/unittests/Demangle/DLangDemangleTest.cpp +++ llvm/unittests/Demangle/DLangDemangleTest.cpp @@ -11,10 +11,11 @@ #include "gtest/gtest.h" #include <cstdlib> +#include <string_view> #include <utility> struct DLangDemangleTestFixture - : public testing::TestWithParam<std::pair<const char *, const char *>> { + : public testing::TestWithParam<std::pair<std::string_view, const char *>> { 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"), Index: llvm/tools/llvm-dlang-demangle-fuzzer/llvm-dlang-demangle-fuzzer.cpp =================================================================== --- llvm/tools/llvm-dlang-demangle-fuzzer/llvm-dlang-demangle-fuzzer.cpp +++ 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; } Index: llvm/lib/Demangle/Demangle.cpp =================================================================== --- llvm/lib/Demangle/Demangle.cpp +++ 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; Index: llvm/lib/Demangle/DLangDemangle.cpp =================================================================== --- llvm/lib/Demangle/DLangDemangle.cpp +++ 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 <cctype> @@ -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; } Index: llvm/include/llvm/Demangle/Demangle.h =================================================================== --- llvm/include/llvm/Demangle/Demangle.h +++ 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. Index: lldb/source/Core/Mangled.cpp =================================================================== --- lldb/source/Core/Mangled.cpp +++ 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");
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits