From ff504b766f18bd4394496a917790c034a26e4d16 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 4 Jun 2019 16:25:28 +0000 Subject: [PATCH] llvm-undname: Yet more coverage for error paths - For error returns in demangleSpecialTableNode(), demangleLocalStaticGuard(), RTTITypeDescriptor, demangleRttiBaseClassDescriptorNode(), demangleUnsigned(), demangleUntypedVariable() (via RttiBaseClassArray) - For ?_A and ?_P which are handled at early levels of the demangler but are not implemented in a later stage; this is now more obvious - Replace a "default:" with an explicit list of cases, to get -Wswitch check we list all cases llvm-svn: 362520 --- lib/Demangle/MicrosoftDemangle.cpp | 11 +++++-- test/Demangle/invalid-manglings.test | 45 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/lib/Demangle/MicrosoftDemangle.cpp b/lib/Demangle/MicrosoftDemangle.cpp index a28e01c2567..450c95ff8a1 100644 --- a/lib/Demangle/MicrosoftDemangle.cpp +++ b/lib/Demangle/MicrosoftDemangle.cpp @@ -429,10 +429,10 @@ FunctionSymbolNode *Demangler::demangleInitFiniStub(StringView &MangledName, SymbolNode *Demangler::demangleSpecialIntrinsic(StringView &MangledName) { SpecialIntrinsicKind SIK = consumeSpecialIntrinsicKind(MangledName); - if (SIK == SpecialIntrinsicKind::None) - return nullptr; switch (SIK) { + case SpecialIntrinsicKind::None: + return nullptr; case SpecialIntrinsicKind::StringLiteralSymbol: return demangleStringLiteral(MangledName); case SpecialIntrinsicKind::Vftable: @@ -468,8 +468,13 @@ SymbolNode *Demangler::demangleSpecialIntrinsic(StringView &MangledName) { return demangleInitFiniStub(MangledName, false); case SpecialIntrinsicKind::DynamicAtexitDestructor: return demangleInitFiniStub(MangledName, true); - default: + case SpecialIntrinsicKind::Typeof: + case SpecialIntrinsicKind::UdtReturning: + // It's unclear which tools produces these manglings, so demangling + // support is not (yet?) implemented. break; + case SpecialIntrinsicKind::Unknown: + DEMANGLE_UNREACHABLE; // Never returned by consumeSpecialIntrinsicKind. } Error = true; return nullptr; diff --git a/test/Demangle/invalid-manglings.test b/test/Demangle/invalid-manglings.test index a5102b9a977..1cc192601a4 100644 --- a/test/Demangle/invalid-manglings.test +++ b/test/Demangle/invalid-manglings.test @@ -309,3 +309,48 @@ ; CHECK-EMPTY: ; CHECK-NEXT: ?foo@?0? ; CHECK-NEXT: error: Invalid mangled name + +??_Sfoo@@1Abar@@ +; CHECK-EMPTY: +; CHECK-NEXT: ??_Sfoo@@1Abar@@ +; CHECK-NEXT: error: Invalid mangled name + +??_Bfoo@@1 +; CHECK-EMPTY: +; CHECK-NEXT: ??_Bfoo@@1 +; CHECK-NEXT: error: Invalid mangled name + +??_R0 +; CHECK-EMPTY: +; CHECK-NEXT: ??_R0 +; CHECK-NEXT: error: Invalid mangled name + +??_R0H +; CHECK-EMPTY: +; CHECK-NEXT: ??_R0H +; CHECK-NEXT: error: Invalid mangled name + +??_R0H@8foo +; CHECK-EMPTY: +; CHECK-NEXT: ??_R0H@8foo +; CHECK-NEXT: error: Invalid mangled name + +??_R1012?3foo@@ +; CHECK-EMPTY: +; CHECK-NEXT: ??_R1012?3foo@@ +; CHECK-NEXT: error: Invalid mangled name + +??_R2foo@@1 +; CHECK-EMPTY: +; CHECK-NEXT: ??_R2foo@@1 +; CHECK-NEXT: error: Invalid mangled name + +??_A +; CHECK-EMPTY: +; CHECK-NEXT: ??_A +; CHECK-NEXT: error: Invalid mangled name + +??_P +; CHECK-EMPTY: +; CHECK-NEXT: ??_P +; CHECK-NEXT: error: Invalid mangled name