[PATCH] D68015: [LLD] Simplify the demangleItanium function. NFC.
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 03:49:34 PDT 2019
mstorsjo created this revision.
mstorsjo added reviewers: ruiu, rnk, MaskRay.
Herald added subscribers: erik.pilkington, aheejin, arichardson, sbc100, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
Instead of returning an optional, just return the input string if demangling fails, as that's what all callers use anyway.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D68015
Files:
lld/Common/Strings.cpp
lld/ELF/SymbolTable.cpp
lld/ELF/Symbols.cpp
lld/include/lld/Common/Strings.h
lld/wasm/Symbols.cpp
Index: lld/wasm/Symbols.cpp
===================================================================
--- lld/wasm/Symbols.cpp
+++ lld/wasm/Symbols.cpp
@@ -304,8 +304,7 @@
std::string lld::maybeDemangleSymbol(StringRef name) {
if (config->demangle)
- if (Optional<std::string> s = demangleItanium(name))
- return *s;
+ return demangleItanium(name);
return name;
}
Index: lld/include/lld/Common/Strings.h
===================================================================
--- lld/include/lld/Common/Strings.h
+++ lld/include/lld/Common/Strings.h
@@ -18,8 +18,8 @@
namespace lld {
// Returns a demangled C++ symbol name. If Name is not a mangled
-// name, it returns Optional::None.
-llvm::Optional<std::string> demangleItanium(llvm::StringRef name);
+// name, it returns name.
+std::string demangleItanium(llvm::StringRef name);
std::vector<uint8_t> parseHex(llvm::StringRef s);
bool isValidCIdentifier(llvm::StringRef s);
Index: lld/ELF/Symbols.cpp
===================================================================
--- lld/ELF/Symbols.cpp
+++ lld/ELF/Symbols.cpp
@@ -45,8 +45,7 @@
// Returns a symbol for an error message.
static std::string demangle(StringRef symName) {
if (config->demangle)
- if (Optional<std::string> s = demangleItanium(symName))
- return *s;
+ return demangleItanium(symName);
return symName;
}
namespace lld {
Index: lld/ELF/SymbolTable.cpp
===================================================================
--- lld/ELF/SymbolTable.cpp
+++ lld/ELF/SymbolTable.cpp
@@ -123,10 +123,7 @@
for (Symbol *sym : symVector) {
if (!sym->isDefined() && !sym->isCommon())
continue;
- if (Optional<std::string> s = demangleItanium(sym->getName()))
- (*demangledSyms)[*s].push_back(sym);
- else
- (*demangledSyms)[sym->getName()].push_back(sym);
+ (*demangledSyms)[demangleItanium(sym->getName())].push_back(sym);
}
}
return *demangledSyms;
Index: lld/Common/Strings.cpp
===================================================================
--- lld/Common/Strings.cpp
+++ lld/Common/Strings.cpp
@@ -18,20 +18,17 @@
using namespace llvm;
using namespace lld;
-// Returns the demangled C++ symbol name for Name.
-Optional<std::string> lld::demangleItanium(StringRef name) {
+// Returns the demangled C++ symbol name for name.
+std::string lld::demangleItanium(StringRef name) {
// itaniumDemangle can be used to demangle strings other than symbol
// names which do not necessarily start with "_Z". Name can be
// either a C or C++ symbol. Don't call demangle if the name
// does not look like a C++ symbol name to avoid getting unexpected
// result for a C symbol that happens to match a mangled type name.
if (!name.startswith("_Z"))
- return None;
+ return name;
- std::string demangled = demangle(name);
- if (demangled == name)
- return None;
- return demangled;
+ return demangle(name);
}
StringMatcher::StringMatcher(ArrayRef<StringRef> pat) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68015.221709.patch
Type: text/x-patch
Size: 3008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190925/7c8161c6/attachment-0001.bin>
More information about the llvm-commits
mailing list