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 @@ -168,7 +168,7 @@ } static char *GetRustV0DemangledStr(const char *M) { - char *demangled_cstr = llvm::rustDemangle(M, nullptr, nullptr, nullptr); + char *demangled_cstr = llvm::rustDemangle(M); if (Log *log = GetLog(LLDBLog::Demangle)) { if (demangled_cstr && demangled_cstr[0]) 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 @@ -57,8 +57,8 @@ size_t *n_buf, int *status, MSDemangleFlags Flags = MSDF_None); -// Demangles a Rust v0 mangled symbol. The API follows that of __cxa_demangle. -char *rustDemangle(const char *MangledName, char *Buf, size_t *N, int *Status); +// Demangles a Rust v0 mangled symbol. +char *rustDemangle(const char *MangledName); // Demangles a D mangled symbol. char *dlangDemangle(const char *MangledName); 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 @@ -51,7 +51,7 @@ if (isItaniumEncoding(MangledName)) Demangled = itaniumDemangle(MangledName, nullptr, nullptr, nullptr); else if (isRustEncoding(MangledName)) - Demangled = rustDemangle(MangledName, nullptr, nullptr, nullptr); + Demangled = rustDemangle(MangledName); else if (isDLangEncoding(MangledName)) Demangled = dlangDemangle(MangledName); diff --git a/llvm/lib/Demangle/RustDemangle.cpp b/llvm/lib/Demangle/RustDemangle.cpp --- a/llvm/lib/Demangle/RustDemangle.cpp +++ b/llvm/lib/Demangle/RustDemangle.cpp @@ -147,57 +147,27 @@ } // namespace -char *llvm::rustDemangle(const char *MangledName, char *Buf, size_t *N, - int *Status) { - if (MangledName == nullptr || (Buf != nullptr && N == nullptr)) { - if (Status != nullptr) - *Status = demangle_invalid_args; +char *llvm::rustDemangle(const char *MangledName) { + if (MangledName == nullptr) return nullptr; - } // Return early if mangled name doesn't look like a Rust symbol. StringView Mangled(MangledName); - if (!Mangled.startsWith("_R")) { - if (Status != nullptr) - *Status = demangle_invalid_mangled_name; + if (!Mangled.startsWith("_R")) return nullptr; - } Demangler D; - if (!initializeOutputBuffer(nullptr, nullptr, D.Output, 1024)) { - if (Status != nullptr) - *Status = demangle_memory_alloc_failure; + if (!initializeOutputBuffer(nullptr, nullptr, D.Output, 1024)) return nullptr; - } if (!D.demangle(Mangled)) { - if (Status != nullptr) - *Status = demangle_invalid_mangled_name; std::free(D.Output.getBuffer()); return nullptr; } D.Output += '\0'; - char *Demangled = D.Output.getBuffer(); - size_t DemangledLen = D.Output.getCurrentPosition(); - - if (Buf != nullptr) { - if (DemangledLen <= *N) { - std::memcpy(Buf, Demangled, DemangledLen); - std::free(Demangled); - Demangled = Buf; - } else { - std::free(Buf); - } - } - - if (N != nullptr) - *N = DemangledLen; - - if (Status != nullptr) - *Status = demangle_success; - return Demangled; + return D.Output.getBuffer(); } Demangler::Demangler(size_t MaxRecursionLevel) diff --git a/llvm/tools/llvm-rust-demangle-fuzzer/llvm-rust-demangle-fuzzer.cpp b/llvm/tools/llvm-rust-demangle-fuzzer/llvm-rust-demangle-fuzzer.cpp --- a/llvm/tools/llvm-rust-demangle-fuzzer/llvm-rust-demangle-fuzzer.cpp +++ b/llvm/tools/llvm-rust-demangle-fuzzer/llvm-rust-demangle-fuzzer.cpp @@ -13,9 +13,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { std::string NullTerminatedString((const char *)Data, Size); - int Status = 0; - char *Demangled = llvm::rustDemangle(NullTerminatedString.c_str(), nullptr, - nullptr, &Status); + char *Demangled = llvm::rustDemangle(NullTerminatedString.c_str()); std::free(Demangled); return 0; } diff --git a/llvm/unittests/Demangle/RustDemangleTest.cpp b/llvm/unittests/Demangle/RustDemangleTest.cpp --- a/llvm/unittests/Demangle/RustDemangleTest.cpp +++ b/llvm/unittests/Demangle/RustDemangleTest.cpp @@ -13,78 +13,19 @@ #include TEST(RustDemangle, Success) { - char *Demangled = - llvm::rustDemangle("_RNvC1a4main", nullptr, nullptr, nullptr); - EXPECT_STREQ(Demangled, "a::main"); - std::free(Demangled); - - // With status. - int Status = 0; - Demangled = llvm::rustDemangle("_RNvC1a4main", nullptr, nullptr, &Status); - EXPECT_EQ(Status, llvm::demangle_success); - EXPECT_STREQ(Demangled, "a::main"); - std::free(Demangled); - - // With status and length. - size_t N = 0; - Demangled = llvm::rustDemangle("_RNvC1a4main", nullptr, &N, &Status); - EXPECT_EQ(Status, llvm::demangle_success); - EXPECT_EQ(N, 8u); + char *Demangled = llvm::rustDemangle("_RNvC1a4main"); EXPECT_STREQ(Demangled, "a::main"); std::free(Demangled); } TEST(RustDemangle, Invalid) { - int Status = 0; char *Demangled = nullptr; // Invalid prefix. - Demangled = llvm::rustDemangle("_ABCDEF", nullptr, nullptr, &Status); - EXPECT_EQ(Status, llvm::demangle_invalid_mangled_name); + Demangled = llvm::rustDemangle("_ABCDEF"); EXPECT_EQ(Demangled, nullptr); // Correct prefix but still invalid. - Demangled = llvm::rustDemangle("_RRR", nullptr, nullptr, &Status); - EXPECT_EQ(Status, llvm::demangle_invalid_mangled_name); + Demangled = llvm::rustDemangle("_RRR"); EXPECT_EQ(Demangled, nullptr); } - -TEST(RustDemangle, OutputBufferWithoutLength) { - char *Buffer = static_cast(std::malloc(1024)); - ASSERT_NE(Buffer, nullptr); - - int Status = 0; - char *Demangled = - llvm::rustDemangle("_RNvC1a4main", Buffer, nullptr, &Status); - - EXPECT_EQ(Status, llvm::demangle_invalid_args); - EXPECT_EQ(Demangled, nullptr); - std::free(Buffer); -} - -TEST(RustDemangle, OutputBuffer) { - size_t N = 1024; - char *Buffer = static_cast(std::malloc(N)); - ASSERT_NE(Buffer, nullptr); - - int Status = 0; - char *Demangled = llvm::rustDemangle("_RNvC1a4main", Buffer, &N, &Status); - - EXPECT_EQ(Status, llvm::demangle_success); - EXPECT_EQ(Demangled, Buffer); - EXPECT_STREQ(Demangled, "a::main"); - std::free(Demangled); -} - -TEST(RustDemangle, SmallOutputBuffer) { - size_t N = 1; - char *Buffer = static_cast(std::malloc(N)); - ASSERT_NE(Buffer, nullptr); - - int Status = 0; - char *Demangled = llvm::rustDemangle("_RNvC1a4main", Buffer, &N, &Status); - - EXPECT_EQ(Status, llvm::demangle_success); - EXPECT_STREQ(Demangled, "a::main"); - std::free(Demangled); -}