Skip to content

Demangler: support protocols as parents of bound generic types to avoid crash in the indexer for invalid swift code. #28609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions test/Demangle/Inputs/manglings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<A1>
$s4test3fooV4blahyAA1SV1fQryFQOy_Qo_AHF ---> test.foo.blah(<<opaque return type of test.S.f() -> some>>.0) -> <<opaque return type of test.S.f() -> some>>.0
$S3nix8MystructV1xACyxGx_tcfc7MyaliasL_ayx__GD ---> Myalias #1 in nix.Mystruct<A>.init(x: A) -> nix.Mystruct<A>
$S3nix7MyclassCfd7MyaliasL_ayx__GD ---> Myalias #1 in nix.Myclass<A>.deinit
Expand Down