[MS Demangler] Don't fail on MD5-mangled names.

When we have an MD5 mangled name, we shouldn't choke and say
that it's an invalid name.  Even though it's impossible to demangle,
we should just output the original name.

llvm-svn: 339891
This commit is contained in:
Zachary Turner 2018-08-16 16:17:17 +00:00
parent 0e18133905
commit 83313f8f54
2 changed files with 25 additions and 1 deletions

View File

@ -213,7 +213,7 @@ enum NameBackrefBehavior : uint8_t {
NBB_Simple = 1 << 1, // save simple names.
};
enum class SymbolCategory { Function, Variable };
enum class SymbolCategory { Function, Variable, Unknown };
namespace {
@ -1051,6 +1051,15 @@ StringView Demangler::copyString(StringView Borrowed) {
Symbol *Demangler::parse(StringView &MangledName) {
Symbol *S = Arena.alloc<Symbol>();
// We can't demangle MD5 names, just output them as-is.
if (MangledName.startsWith("??@")) {
S->Category = SymbolCategory::Unknown;
S->SymbolName = Arena.alloc<Name>();
S->SymbolName->Str = MangledName;
MangledName = StringView();
return S;
}
// MSVC-style mangled symbols must start with '?'.
if (!MangledName.consumeFront("?")) {
S->SymbolName = Arena.alloc<Name>();
@ -2180,6 +2189,10 @@ StringView Demangler::resolve(StringView N) {
}
void Demangler::output(const Symbol *S, OutputStream &OS) {
if (S->Category == SymbolCategory::Unknown) {
outputName(OS, S->SymbolName, S->SymbolType, *this);
return;
}
// Converts an AST to a string.
//
// Converting an AST representing a C++ type to a string is tricky due

View File

@ -0,0 +1,11 @@
; These tests are based on clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
; RUN: llvm-undname < %s | FileCheck %s
; CHECK-NOT: Invalid mangled name
; MD5-mangled names start with ??@ and we should output them as is. We have
; two check lines here since the tool echos the input.
??@a6a285da2eea70dba6b578022be61d81@
; CHECK: ??@a6a285da2eea70dba6b578022be61d81@
; CHECK-NEXT: ??@a6a285da2eea70dba6b578022be61d81@