[llvm] 2597135 - [llvm-cxxfilt] Correctly demangle COFF import thunk
Steven Wu via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 16 09:50:26 PST 2019
Author: Steven Wu
Date: 2019-12-16T09:50:04-08:00
New Revision: 2597135571ecae435e10e9136d1eb0435beca8ee
URL: https://github.com/llvm/llvm-project/commit/2597135571ecae435e10e9136d1eb0435beca8ee
DIFF: https://github.com/llvm/llvm-project/commit/2597135571ecae435e10e9136d1eb0435beca8ee.diff
LOG: [llvm-cxxfilt] Correctly demangle COFF import thunk
Summary:
llvm-cxxfilt wasn't correctly demangle COFF import thunk in those two
cases before:
* demangle in split mode (multiple words from commandline)
* the import thunk prefix was added no matter the later part of the
string can be demangled or not
Now llvm-cxxfilt should handle both case correctly.
Reviewers: compnerd, erik.pilkington, jhenderson
Reviewed By: jhenderson
Subscribers: jkorous, dexonsmith, ributzka, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71425
Added:
Modified:
llvm/test/tools/llvm-cxxfilt/coff-import.test
llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-cxxfilt/coff-import.test b/llvm/test/tools/llvm-cxxfilt/coff-import.test
index 409fd88e595d..40d01c7f7dbd 100644
--- a/llvm/test/tools/llvm-cxxfilt/coff-import.test
+++ b/llvm/test/tools/llvm-cxxfilt/coff-import.test
@@ -1,5 +1,12 @@
RUN: llvm-cxxfilt -_ ___imp__ZSt6futureIvE | FileCheck %s
RUN: llvm-cxxfilt -n __imp__ZSt6futureIvE | FileCheck %s
-CHECK: import thunk for std::future<void>
+## This should not demangle
+RUN: llvm-cxxfilt -n __imp__foo | FileCheck %s --check-prefix=CHECK-STRING --match-full-lines
+
+RUN: echo "__imp__ZSt6futureIvE __imp__ZSt6futureIvE" | llvm-cxxfilt -n | \
+RUN: FileCheck %s --check-prefix=CHECK-SPLIT
+CHECK: import thunk for std::future<void>
+CHECK-STRING: __imp__foo
+CHECK-SPLIT: import thunk for std::future<void> import thunk for std::future<void>
diff --git a/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
index 75d6985133a1..6de512fc18dc 100644
--- a/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
+++ b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
@@ -74,8 +74,9 @@ static bool shouldStripUnderscore() {
return Triple(sys::getProcessTriple()).isOSBinFormatMachO();
}
-static std::string demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
+static std::string demangle(const std::string &Mangled) {
int Status;
+ std::string Prefix;
const char *DecoratedStr = Mangled.c_str();
if (shouldStripUnderscore())
@@ -92,11 +93,11 @@ static std::string demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
if (!Undecorated &&
(DecoratedLength > 6 && strncmp(DecoratedStr, "__imp_", 6) == 0)) {
- OS << "import thunk for ";
+ Prefix = "import thunk for ";
Undecorated = itaniumDemangle(DecoratedStr + 6, nullptr, nullptr, &Status);
}
- std::string Result(Undecorated ? Undecorated : Mangled);
+ std::string Result(Undecorated ? Prefix + Undecorated : Mangled);
free(Undecorated);
return Result;
}
@@ -144,9 +145,9 @@ static void demangleLine(llvm::raw_ostream &OS, StringRef Mangled, bool Split) {
SmallVector<std::pair<StringRef, StringRef>, 16> Words;
SplitStringDelims(Mangled, Words, IsLegalItaniumChar);
for (const auto &Word : Words)
- Result += demangle(OS, Word.first) + Word.second.str();
+ Result += ::demangle(Word.first) + Word.second.str();
} else
- Result = demangle(OS, Mangled);
+ Result = ::demangle(Mangled);
OS << Result << '\n';
OS.flush();
}
More information about the llvm-commits
mailing list