[llvm] 3b01fa2 - [Demangle] remove unused status param of itaniumDemangle
Nick Desaulniers via llvm-commits
llvm-commits at lists.llvm.org
Wed May 3 11:58:04 PDT 2023
Author: Nick Desaulniers
Date: 2023-05-03T11:51:35-07:00
New Revision: 3b01fa264c36c1c7bb293f001579e0f459a92b84
URL: https://github.com/llvm/llvm-project/commit/3b01fa264c36c1c7bb293f001579e0f459a92b84
DIFF: https://github.com/llvm/llvm-project/commit/3b01fa264c36c1c7bb293f001579e0f459a92b84.diff
LOG: [Demangle] remove unused status param of itaniumDemangle
No call sites interpreted this value meaningfully. Simplify this
interface.
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D149707
Added:
Modified:
llvm/include/llvm/Demangle/Demangle.h
llvm/lib/Demangle/Demangle.cpp
llvm/lib/Demangle/ItaniumDemangle.cpp
llvm/lib/ProfileData/GCOV.cpp
llvm/lib/Support/Unix/Signals.inc
llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
llvm/tools/llvm-itanium-demangle-fuzzer/llvm-itanium-demangle-fuzzer.cpp
llvm/tools/llvm-objdump/MachODump.cpp
llvm/tools/llvm-opt-report/OptReport.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Demangle/Demangle.h b/llvm/include/llvm/Demangle/Demangle.h
index 7a2471b9710ba..f41fdc2c0cba3 100644
--- a/llvm/include/llvm/Demangle/Demangle.h
+++ b/llvm/include/llvm/Demangle/Demangle.h
@@ -28,7 +28,10 @@ enum : int {
demangle_success = 0,
};
-char *itaniumDemangle(const char *mangled_name, int *status);
+/// Returns a non-NULL pointer to a NUL-terminated C style string
+/// that should be explicitly freed, if successful. Otherwise, may return
+/// nullptr if mangled_name is not a valid mangling or is nullptr.
+char *itaniumDemangle(const char *mangled_name);
enum MSDemangleFlags {
MSDF_None = 0,
diff --git a/llvm/lib/Demangle/Demangle.cpp b/llvm/lib/Demangle/Demangle.cpp
index d80f3f9715073..87603603cb4ac 100644
--- a/llvm/lib/Demangle/Demangle.cpp
+++ b/llvm/lib/Demangle/Demangle.cpp
@@ -48,7 +48,7 @@ std::string llvm::demangle(const std::string &MangledName) {
bool llvm::nonMicrosoftDemangle(const char *MangledName, std::string &Result) {
char *Demangled = nullptr;
if (isItaniumEncoding(MangledName))
- Demangled = itaniumDemangle(MangledName, nullptr);
+ Demangled = itaniumDemangle(MangledName);
else if (isRustEncoding(MangledName))
Demangled = rustDemangle(MangledName);
else if (isDLangEncoding(MangledName))
diff --git a/llvm/lib/Demangle/ItaniumDemangle.cpp b/llvm/lib/Demangle/ItaniumDemangle.cpp
index e97ceebce1e76..b1a8832f1b32a 100644
--- a/llvm/lib/Demangle/ItaniumDemangle.cpp
+++ b/llvm/lib/Demangle/ItaniumDemangle.cpp
@@ -365,31 +365,20 @@ class DefaultAllocator {
using Demangler = itanium_demangle::ManglingParser<DefaultAllocator>;
-char *llvm::itaniumDemangle(const char *MangledName, int *Status) {
- if (MangledName == nullptr) {
- if (Status)
- *Status = demangle_invalid_args;
+char *llvm::itaniumDemangle(const char *MangledName) {
+ if (!MangledName)
return nullptr;
- }
- int InternalStatus = demangle_success;
Demangler Parser(MangledName, MangledName + std::strlen(MangledName));
Node *AST = Parser.parse();
+ if (!AST)
+ return nullptr;
- char *Buf;
- if (AST == nullptr)
- InternalStatus = demangle_invalid_mangled_name;
- else {
- OutputBuffer OB;
- assert(Parser.ForwardTemplateRefs.empty());
- AST->print(OB);
- OB += '\0';
- Buf = OB.getBuffer();
- }
-
- if (Status)
- *Status = InternalStatus;
- return InternalStatus == demangle_success ? Buf : nullptr;
+ OutputBuffer OB;
+ assert(Parser.ForwardTemplateRefs.empty());
+ AST->print(OB);
+ OB += '\0';
+ return OB.getBuffer();
}
ItaniumPartialDemangler::ItaniumPartialDemangler()
diff --git a/llvm/lib/ProfileData/GCOV.cpp b/llvm/lib/ProfileData/GCOV.cpp
index 416624252e485..e922f8cff9e60 100644
--- a/llvm/lib/ProfileData/GCOV.cpp
+++ b/llvm/lib/ProfileData/GCOV.cpp
@@ -337,10 +337,8 @@ StringRef GCOVFunction::getName(bool demangle) const {
if (demangled.empty()) {
do {
if (Name.startswith("_Z")) {
- int status = 0;
// Name is guaranteed to be NUL-terminated.
- char *res = itaniumDemangle(Name.data(), &status);
- if (status == 0) {
+ if (char *res = itaniumDemangle(Name.data())) {
demangled = res;
free(res);
break;
diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index 46313d9111cc5..fcf5701afcfd4 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -652,13 +652,12 @@ void llvm::sys::PrintStackTrace(raw_ostream &OS, int Depth) {
if (dlinfo.dli_sname != nullptr) {
OS << ' ';
- int res;
- char *d = itaniumDemangle(dlinfo.dli_sname, &res);
- if (!d)
- OS << dlinfo.dli_sname;
- else
+ if (char *d = itaniumDemangle(dlinfo.dli_sname)) {
OS << d;
- free(d);
+ free(d);
+ } else {
+ OS << dlinfo.dli_sname;
+ }
OS << format(" + %tu", (static_cast<const char *>(StackTrace[i]) -
static_cast<const char *>(dlinfo.dli_saddr)));
diff --git a/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
index 4e7a396565a65..109c1b27e5872 100644
--- a/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
+++ b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
@@ -84,11 +84,11 @@ static std::string demangle(const std::string &Mangled) {
char *Undecorated = nullptr;
if (Types)
- Undecorated = itaniumDemangle(DecoratedStr, nullptr);
+ Undecorated = itaniumDemangle(DecoratedStr);
if (!Undecorated && strncmp(DecoratedStr, "__imp_", 6) == 0) {
Prefix = "import thunk for ";
- Undecorated = itaniumDemangle(DecoratedStr + 6, nullptr);
+ Undecorated = itaniumDemangle(DecoratedStr + 6);
}
Result = Undecorated ? Prefix + Undecorated : Mangled;
diff --git a/llvm/tools/llvm-itanium-demangle-fuzzer/llvm-itanium-demangle-fuzzer.cpp b/llvm/tools/llvm-itanium-demangle-fuzzer/llvm-itanium-demangle-fuzzer.cpp
index 8bb58e1cd7173..6d2dc7d5774c9 100644
--- a/llvm/tools/llvm-itanium-demangle-fuzzer/llvm-itanium-demangle-fuzzer.cpp
+++ b/llvm/tools/llvm-itanium-demangle-fuzzer/llvm-itanium-demangle-fuzzer.cpp
@@ -14,9 +14,7 @@
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
std::string NullTerminatedString((const char *)Data, Size);
- int status = 0;
- if (char *demangle =
- llvm::itaniumDemangle(NullTerminatedString.c_str(), &status))
+ if (char *demangle = llvm::itaniumDemangle(NullTerminatedString.c_str()))
free(demangle);
return 0;
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp
index 7b70a340f63dc..5253943e333bf 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -7280,8 +7280,7 @@ static const char *SymbolizerSymbolLookUp(void *DisInfo,
} else if (SymbolName != nullptr && strncmp(SymbolName, "__Z", 3) == 0) {
if (info->demangled_name != nullptr)
free(info->demangled_name);
- int status;
- info->demangled_name = itaniumDemangle(SymbolName + 1, &status);
+ info->demangled_name = itaniumDemangle(SymbolName + 1);
if (info->demangled_name != nullptr) {
*ReferenceName = info->demangled_name;
*ReferenceType = LLVMDisassembler_ReferenceType_DeMangled_Name;
@@ -7379,8 +7378,7 @@ static const char *SymbolizerSymbolLookUp(void *DisInfo,
} else if (SymbolName != nullptr && strncmp(SymbolName, "__Z", 3) == 0) {
if (info->demangled_name != nullptr)
free(info->demangled_name);
- int status;
- info->demangled_name = itaniumDemangle(SymbolName + 1, &status);
+ info->demangled_name = itaniumDemangle(SymbolName + 1);
if (info->demangled_name != nullptr) {
*ReferenceName = info->demangled_name;
*ReferenceType = LLVMDisassembler_ReferenceType_DeMangled_Name;
diff --git a/llvm/tools/llvm-opt-report/OptReport.cpp b/llvm/tools/llvm-opt-report/OptReport.cpp
index 51fa237ae4de4..aa7a33d0af839 100644
--- a/llvm/tools/llvm-opt-report/OptReport.cpp
+++ b/llvm/tools/llvm-opt-report/OptReport.cpp
@@ -338,15 +338,11 @@ static bool writeReport(LocationInfoTy &LocationInfo) {
bool Printed = false;
if (!NoDemangle) {
- int Status = 0;
- char *Demangled = itaniumDemangle(FuncName.c_str(), &Status);
- if (Demangled && Status == 0) {
+ if (char *Demangled = itaniumDemangle(FuncName.c_str())) {
OS << Demangled;
Printed = true;
- }
-
- if (Demangled)
std::free(Demangled);
+ }
}
if (!Printed)
More information about the llvm-commits
mailing list