1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

llvm-cxxfilt: filter out invalid manglings

c++filt does not attempt to demangle symbols which do not match its
expected format.  This means that the symbol must start with _Z or ___Z
(block invocation function extension).  Any other symbols are returned
as is.  Note that this is different from the behaviour of __cxa_demangle
which will demangle fragments.

llvm-svn: 292467
This commit is contained in:
Saleem Abdulrasool 2017-01-19 02:58:46 +00:00
parent abe1662e38
commit 1471b048f9
2 changed files with 12 additions and 3 deletions

View File

@ -0,0 +1,6 @@
RUN: llvm-cxxfilt _Z1fi __Z1fi f ___ZSt1ff_block_invoke | FileCheck %s
CHECK: f(int)
CHECK-NEXT: __Z1fi
CHECK-NEXT: f
CHECK-NEXT: invocation function for block in std::f(float)

View File

@ -14,9 +14,12 @@
using namespace llvm;
static void demangle(llvm::raw_ostream &OS, const char *Mangled) {
static void demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
int Status;
char *Demangled = itaniumDemangle(Mangled, nullptr, nullptr, &Status);
char *Demangled = nullptr;
if ((Mangled.size() >= 2 && Mangled.compare(0, 2, "_Z")) ||
(Mangled.size() >= 4 && Mangled.compare(0, 4, "___Z")))
Demangled = itaniumDemangle(Mangled.c_str(), nullptr, nullptr, &Status);
OS << (Demangled ? Demangled : Mangled) << '\n';
free(Demangled);
}
@ -24,7 +27,7 @@ static void demangle(llvm::raw_ostream &OS, const char *Mangled) {
int main(int argc, char **argv) {
if (argc == 1)
for (std::string Mangled; std::getline(std::cin, Mangled);)
demangle(llvm::outs(), Mangled.c_str());
demangle(llvm::outs(), Mangled);
else
for (int I = 1; I < argc; ++I)
demangle(llvm::outs(), argv[I]);