[LLD] Convert demangleItanium to use the higher level llvm::demangle function. NFC.

This avoids a few lines of boilerplate of dealing with C string
allocations.

Add a testcase for a case where demangling shouldn't happen.

Differential Revision: https://reviews.llvm.org/D68014

llvm-svn: 373076
This commit is contained in:
Martin Storsjo 2019-09-27 12:24:03 +00:00
parent bf6f4e9932
commit dd71b2d4c3
2 changed files with 9 additions and 6 deletions

View File

@ -22,18 +22,16 @@ using namespace lld;
Optional<std::string> lld::demangleItanium(StringRef name) { Optional<std::string> lld::demangleItanium(StringRef name) {
// itaniumDemangle can be used to demangle strings other than symbol // itaniumDemangle can be used to demangle strings other than symbol
// names which do not necessarily start with "_Z". Name can be // names which do not necessarily start with "_Z". Name can be
// either a C or C++ symbol. Don't call itaniumDemangle if the name // 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 // 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. // result for a C symbol that happens to match a mangled type name.
if (!name.startswith("_Z")) if (!name.startswith("_Z"))
return None; return None;
char *buf = itaniumDemangle(name.str().c_str(), nullptr, nullptr, nullptr); std::string demangled = demangle(name);
if (!buf) if (demangled == name)
return None; return None;
std::string s(buf); return demangled;
free(buf);
return s;
} }
StringMatcher::StringMatcher(ArrayRef<StringRef> pat) { StringMatcher::StringMatcher(ArrayRef<StringRef> pat) {

View File

@ -23,6 +23,10 @@
# CHECK: error: undefined symbol: vtable for Foo # CHECK: error: undefined symbol: vtable for Foo
# CHECK: the vtable symbol may be undefined because the class is missing its key function (see https://lld.llvm.org/missingkeyfunction) # CHECK: the vtable symbol may be undefined because the class is missing its key function (see https://lld.llvm.org/missingkeyfunction)
# CHECK: error: undefined symbol: __Z3fooi
# CHECK: >>> referenced by undef.s
# CHECK: >>> {{.*}}:(.text+0x1A)
# CHECK: error: undefined symbol: zed2 # CHECK: error: undefined symbol: zed2
# CHECK: >>> referenced by {{.*}}.o:(.text+0x0) in archive {{.*}}2.a # CHECK: >>> referenced by {{.*}}.o:(.text+0x0) in archive {{.*}}2.a
@ -64,3 +68,4 @@ _start:
call zed1 call zed1
call _Z3fooi call _Z3fooi
call _ZTV3Foo call _ZTV3Foo
call __Z3fooi