[PATCH] D71425: [llvm-cxxfilt] Correctly demangle COFF import thunk
Steven Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 12 09:28:20 PST 2019
steven_wu created this revision.
steven_wu added reviewers: compnerd, erik.pilkington.
Herald added subscribers: ributzka, dexonsmith, jkorous.
Herald added a reviewer: jhenderson.
Herald added a project: LLVM.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71425
Files:
llvm/test/tools/llvm-cxxfilt/coff-import.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
@@ -74,8 +74,9 @@
return Triple(sys::getProcessTriple()).isOSBinFormatMachO();
}
-static std::string demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
+static std::string demangleWord(const std::string &Mangled) {
int Status;
+ std::string Prefix;
const char *DecoratedStr = Mangled.c_str();
if (shouldStripUnderscore())
@@ -92,11 +93,11 @@
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 @@
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 += demangleWord(Word.first) + Word.second.str();
} else
- Result = demangle(OS, Mangled);
+ Result = demangleWord(Mangled);
OS << Result << '\n';
OS.flush();
}
Index: llvm/test/tools/llvm-cxxfilt/coff-import.test
===================================================================
--- llvm/test/tools/llvm-cxxfilt/coff-import.test
+++ llvm/test/tools/llvm-cxxfilt/coff-import.test
@@ -1,5 +1,13 @@
RUN: llvm-cxxfilt -_ ___imp__ZSt6futureIvE | FileCheck %s
RUN: llvm-cxxfilt -n __imp__ZSt6futureIvE | FileCheck %s
-CHECK: import thunk for std::future<void>
+# This should demangle to origin string
+RUN: llvm-cxxfilt -n __imp__foo | FileCheck %s --check-prefix=CHECK-STRING
+
+RUN: llvm-cxxfilt -n __imp__ZSt6futureIvE __imp__ZSt6futureIvE | \
+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>
+CHECK-SPLIT-NEXT: import thunk for std::future<void>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71425.233642.patch
Type: text/x-patch
Size: 2244 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191212/c10361d4/attachment.bin>
More information about the llvm-commits
mailing list