[PATCH] D57350: [llvm-cxxfilt] Split input and demangle each word.
Matt Davis via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 28 11:51:44 PST 2019
mattd created this revision.
mattd added a reviewer: compnerd.
Herald added a subscriber: erik.pilkington.
Originally, llvm-cxxfilt would only demangle an entire line/string of input. However, if a mangled name appears in the middle of that string, that name would not be demangled.
This patch splits the string into separate words and demangles each word.
This fixes PR39990
https://reviews.llvm.org/D57350
Files:
llvm/test/tools/llvm-cxxfilt/simple.test
llvm/test/tools/llvm-cxxfilt/types.test
llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
Index: llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
===================================================================
--- llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
+++ llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
@@ -6,6 +6,9 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
@@ -51,7 +54,7 @@
static cl::list<std::string>
Decorated(cl::Positional, cl::desc("<mangled>"), cl::ZeroOrMore);
-static void demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
+static std::string demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
int Status;
const char *Decorated = Mangled.c_str();
@@ -72,10 +75,24 @@
Undecorated = itaniumDemangle(Decorated + 6, nullptr, nullptr, &Status);
}
- OS << (Undecorated ? Undecorated : Mangled) << '\n';
- OS.flush();
-
+ std::string Result(Undecorated ? Undecorated : Mangled);
free(Undecorated);
+ return Result;
+}
+
+// Split 'Mangled' and demangle each word.
+// The result is reconstructed and output to 'OS'.
+static void demangleLine(llvm::raw_ostream &OS, const std::string &Mangled) {
+ SmallVector<StringRef, 16> Words;
+ SplitString(Mangled, Words);
+ std::string Result;
+ for (auto Word : Words)
+ Result += demangle(OS, Word) + ' ';
+ // Remove the trailing space character.
+ if (Result.back() == ' ')
+ Result.pop_back();
+ OS << Result << '\n';
+ OS.flush();
}
int main(int argc, char **argv) {
@@ -85,10 +102,10 @@
if (Decorated.empty())
for (std::string Mangled; std::getline(std::cin, Mangled);)
- demangle(llvm::outs(), Mangled);
+ demangleLine(llvm::outs(), Mangled);
else
for (const auto &Symbol : Decorated)
- demangle(llvm::outs(), Symbol);
+ demangleLine(llvm::outs(), Symbol);
return EXIT_SUCCESS;
}
Index: llvm/test/tools/llvm-cxxfilt/types.test
===================================================================
--- llvm/test/tools/llvm-cxxfilt/types.test
+++ llvm/test/tools/llvm-cxxfilt/types.test
@@ -1,5 +1,6 @@
RUN: llvm-cxxfilt -t f i | FileCheck %s
+RUN: llvm-cxxfilt -t "f i" | FileCheck %s --check-prefix="CHECK-STRING"
CHECK: float
CHECK-NEXT: int
-
+CHECK-STRING: float int
Index: llvm/test/tools/llvm-cxxfilt/simple.test
===================================================================
--- llvm/test/tools/llvm-cxxfilt/simple.test
+++ llvm/test/tools/llvm-cxxfilt/simple.test
@@ -1,4 +1,6 @@
RUN: llvm-cxxfilt _Z1fi abc | FileCheck %s
+RUN: llvm-cxxfilt "Mangled _Z1fi and _Z3foov in string." | FileCheck %s --check-prefix=CHECK-STRING
CHECK: f(int)
CHECK-NEXT: abc
+CHECK-STRING: Mangled f(int) and foo() in string.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57350.183917.patch
Type: text/x-patch
Size: 2859 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190128/7bb591ec/attachment.bin>
More information about the llvm-commits
mailing list