Skip to content

[Demangler] Fix OldRemangler's handling of Subscript nodes. #38223

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 2 commits into from
Jul 7, 2021
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
3 changes: 3 additions & 0 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3410,6 +3410,9 @@ NodePointer Demangler::demangleSubscript() {
NodePointer LabelList = popFunctionParamLabels(Type);
NodePointer Context = popContext();

if (!Type)
return nullptr;

NodePointer Subscript = createNode(Node::Kind::Subscript);
Subscript = addChild(Subscript, Context);
addChild(Subscript, LabelList);
Expand Down
15 changes: 14 additions & 1 deletion lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,20 @@ void Remangler::mangleVariable(Node *node, EntityContext &ctx, unsigned depth) {

void Remangler::mangleSubscript(Node *node, EntityContext &ctx,
unsigned depth) {
mangleNamedAndTypedEntity(node, 'i', "", ctx, depth + 1);
assert(node->getNumChildren() >= 2);
Buffer << 'i';
mangleEntityContext(node->begin()[0], ctx, depth + 1);
if (node->getLastChild()->getKind() == Node::Kind::PrivateDeclName)
mangle(node->getLastChild(), depth + 1);

if (node->getNumChildren() >= 3
&& node->begin()[1]->getKind() == Node::Kind::LabelList) {
auto LabelList = node->begin()[1];
auto Type = node->begin()[2];
mangleEntityType(applyParamLabels(LabelList, Type, Factory), ctx, depth + 1);
} else {
mangleEntityType(node->begin()[1], ctx, depth + 1);
}
}

void Remangler::mangleAccessor(Node *storageNode, StringRef accessorCode,
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 @@ -412,4 +412,5 @@ $s4test10returnsOptyxycSgxyScMYccSglF ---> test.returnsOpt<A>((@Swift.MainActor
$sSvSgA3ASbIetCyyd_SgSbIetCyyyd_SgD ---> (@escaping @convention(thin) @convention(c) (@unowned Swift.UnsafeMutableRawPointer?, @unowned Swift.UnsafeMutableRawPointer?, @unowned (@escaping @convention(thin) @convention(c) (@unowned Swift.UnsafeMutableRawPointer?, @unowned Swift.UnsafeMutableRawPointer?) -> (@unowned Swift.Bool))?) -> (@unowned Swift.Bool))?
$s4test10returnsOptyxycSgxyScMYccSglF ---> test.returnsOpt<A>((@Swift.MainActor () -> A)?) -> (() -> A)?
$s1t10globalFuncyyAA7MyActorCYiF ---> t.globalFunc(isolated t.MyActor) -> ()
$sSIxip6foobarP ---> foobar in Swift.DefaultIndices.subscript : A
$s13__lldb_expr_110$10016c2d8yXZ1B10$10016c2e0LLC ---> __lldb_expr_1.(unknown context at $10016c2d8).(B in $10016c2e0)
3 changes: 3 additions & 0 deletions test/Demangle/remangle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ RUN: swift-demangle -remangle-objc-rt '$sSiStMSLB_p' | %FileCheck -check-prefix
// CHECK-OLD3: Swift.related decl 'H' for partial apply forwarder
RUN: swift-demangle -remangle-objc-rt '$ssTALHP' | %FileCheck -check-prefix CHECK-OLD3 %s

// CHECK-OLD4: foobar in Swift.DefaultIndices.subscript : A
RUN: swift-demangle -remangle-objc-rt '$sSIxip6foobarP' | %FileCheck -check-prefix CHECK-OLD4 %s

// CHECK-GENERICEXT: Swift._ContiguousArrayStorage<(extension in Swift):Swift.FlattenSequence<StdlibCollectionUnittest.MinimalBidirectionalCollection<StdlibCollectionUnittest.MinimalBidirectionalCollection<Swift.Int>>>.Index>
RUN: swift-demangle -remangle-objc-rt '$ss23_ContiguousArrayStorageCys15FlattenSequenceVsE5IndexVy24StdlibCollectionUnittest020MinimalBidirectionalH0VyAIySiGG_GGD' | %FileCheck -check-prefix CHECK-GENERICEXT %s