From f860a9b73f9d4582487459855dc2e19446258a1b Mon Sep 17 00:00:00 2001 From: Erik Eckstein Date: Fri, 6 Dec 2019 15:16:46 +0100 Subject: [PATCH] Demangler: support protocols as parents of bound generic types to avoid crash in the indexer for invalid swift code. rdar://problem/57533567 --- lib/Demangling/Remangler.cpp | 6 ++++++ test/Demangle/Inputs/manglings.txt | 1 + 2 files changed, 7 insertions(+) diff --git a/lib/Demangling/Remangler.cpp b/lib/Demangling/Remangler.cpp index ecb972dcc0006..af898208fb5c3 100644 --- a/lib/Demangling/Remangler.cpp +++ b/lib/Demangling/Remangler.cpp @@ -487,6 +487,12 @@ void Remangler::mangleAnyNominalType(Node *node) { void Remangler::mangleGenericArgs(Node *node, char &Separator, bool fullSubstitutionMap) { switch (node->getKind()) { + case Node::Kind::Protocol: + // A protocol cannot be the parent of a nominal type, so this case should + // never be hit by valid swift code. But the indexer might generate a URL + // from invalid swift code, which has a bound generic inside a protocol. + // The ASTMangler treats a protocol like any other nominal type in this + // case, so we also support it in the remangler. case Node::Kind::Structure: case Node::Kind::Enum: case Node::Kind::Class: diff --git a/test/Demangle/Inputs/manglings.txt b/test/Demangle/Inputs/manglings.txt index 274d66bb57f96..d52840d75bd92 100644 --- a/test/Demangle/Inputs/manglings.txt +++ b/test/Demangle/Inputs/manglings.txt @@ -328,6 +328,7 @@ _$S3BBBBf0602365061_ ---> _$S3BBBBf0602365061_ _$S3BBBBi0602365061_ ---> _$S3BBBBi0602365061_ _$S3BBBBv0602365061_ ---> _$S3BBBBv0602365061_ _T0lxxxmmmTk ---> _T0lxxxmmmTk +$s4Test5ProtoP8IteratorV10collectionAEy_qd__Gqd___tcfc ---> Test.Proto.Iterator.init(collection: A1) -> Test.Proto.Iterator $s4test3fooV4blahyAA1SV1fQryFQOy_Qo_AHF ---> test.foo.blah(< some>>.0) -> < some>>.0 $S3nix8MystructV1xACyxGx_tcfc7MyaliasL_ayx__GD ---> Myalias #1 in nix.Mystruct.init(x: A) -> nix.Mystruct $S3nix7MyclassCfd7MyaliasL_ayx__GD ---> Myalias #1 in nix.Myclass.deinit