[lld] r373077 - [LLD] Simplify the demangleItanium function. NFC.
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 27 05:24:19 PDT 2019
Author: mstorsjo
Date: Fri Sep 27 05:24:18 2019
New Revision: 373077
URL: http://llvm.org/viewvc/llvm-project?rev=373077&view=rev
Log:
[LLD] Simplify the demangleItanium function. NFC.
Instead of returning an optional, just return the input string if
demangling fails, as that's what all callers use anyway.
Differential Revision: https://reviews.llvm.org/D68015
Modified:
lld/trunk/Common/Strings.cpp
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/Symbols.cpp
lld/trunk/include/lld/Common/Strings.h
lld/trunk/wasm/Symbols.cpp
Modified: lld/trunk/Common/Strings.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/Common/Strings.cpp?rev=373077&r1=373076&r2=373077&view=diff
==============================================================================
--- lld/trunk/Common/Strings.cpp (original)
+++ lld/trunk/Common/Strings.cpp Fri Sep 27 05:24:18 2019
@@ -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) {
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=373077&r1=373076&r2=373077&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Fri Sep 27 05:24:18 2019
@@ -123,10 +123,7 @@ StringMap<std::vector<Symbol *>> &Symbol
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;
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=373077&r1=373076&r2=373077&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Fri Sep 27 05:24:18 2019
@@ -45,8 +45,7 @@ Defined *ElfSym::tlsModuleBase;
// 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 {
Modified: lld/trunk/include/lld/Common/Strings.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Common/Strings.h?rev=373077&r1=373076&r2=373077&view=diff
==============================================================================
--- lld/trunk/include/lld/Common/Strings.h (original)
+++ lld/trunk/include/lld/Common/Strings.h Fri Sep 27 05:24:18 2019
@@ -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);
Modified: lld/trunk/wasm/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.cpp?rev=373077&r1=373076&r2=373077&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.cpp (original)
+++ lld/trunk/wasm/Symbols.cpp Fri Sep 27 05:24:18 2019
@@ -304,8 +304,7 @@ std::string lld::toString(const wasm::Sy
std::string lld::maybeDemangleSymbol(StringRef name) {
if (config->demangle)
- if (Optional<std::string> s = demangleItanium(name))
- return *s;
+ return demangleItanium(name);
return name;
}
More information about the llvm-commits
mailing list