Skip to content

Commit 779b10d

Browse files
committed
[Demangler] Fix OldRemangler's handling of Subscript nodes.
The Subscript node isn't laid-out the way the code in OldRemangler thinks, which has the unfortunate result of causing crashes. rdar://63410196
1 parent 92b7e13 commit 779b10d

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3410,6 +3410,9 @@ NodePointer Demangler::demangleSubscript() {
34103410
NodePointer LabelList = popFunctionParamLabels(Type);
34113411
NodePointer Context = popContext();
34123412

3413+
if (!Type)
3414+
return nullptr;
3415+
34133416
NodePointer Subscript = createNode(Node::Kind::Subscript);
34143417
Subscript = addChild(Subscript, Context);
34153418
addChild(Subscript, LabelList);

lib/Demangling/OldRemangler.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,20 @@ void Remangler::mangleVariable(Node *node, EntityContext &ctx, unsigned depth) {
874874

875875
void Remangler::mangleSubscript(Node *node, EntityContext &ctx,
876876
unsigned depth) {
877-
mangleNamedAndTypedEntity(node, 'i', "", ctx, depth + 1);
877+
assert(node->getNumChildren() >= 2);
878+
Buffer << 'i';
879+
mangleEntityContext(node->begin()[0], ctx, depth + 1);
880+
if (node->getLastChild()->getKind() == Node::Kind::PrivateDeclName)
881+
mangle(node->getLastChild(), depth + 1);
882+
883+
if (node->getNumChildren() >= 3
884+
&& node->begin()[1]->getKind() == Node::Kind::LabelList) {
885+
auto LabelList = node->begin()[1];
886+
auto Type = node->begin()[2];
887+
mangleEntityType(applyParamLabels(LabelList, Type, Factory), ctx, depth + 1);
888+
} else {
889+
mangleEntityType(node->begin()[1], ctx, depth + 1);
890+
}
878891
}
879892

880893
void Remangler::mangleAccessor(Node *storageNode, StringRef accessorCode,

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,4 @@ $s4test10returnsOptyxycSgxyScMYccSglF ---> test.returnsOpt<A>((@Swift.MainActor
412412
$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))?
413413
$s4test10returnsOptyxycSgxyScMYccSglF ---> test.returnsOpt<A>((@Swift.MainActor () -> A)?) -> (() -> A)?
414414
$s1t10globalFuncyyAA7MyActorCYiF ---> t.globalFunc(isolated t.MyActor) -> ()
415+
$sSIxip6foobarP ---> foobar in Swift.DefaultIndices.subscript : A

test/Demangle/remangle.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ RUN: swift-demangle -remangle-objc-rt '$sSiStMSLB_p' | %FileCheck -check-prefix
1515
// CHECK-OLD3: Swift.related decl 'H' for partial apply forwarder
1616
RUN: swift-demangle -remangle-objc-rt '$ssTALHP' | %FileCheck -check-prefix CHECK-OLD3 %s
1717

18+
// CHECK-OLD4: foobar in Swift.DefaultIndices.subscript : A
19+
RUN: swift-demangle -remangle-objc-rt '$sSIxip6foobarP' | %FileCheck -check-prefix CHECK-OLD4 %s
20+
1821
// CHECK-GENERICEXT: Swift._ContiguousArrayStorage<(extension in Swift):Swift.FlattenSequence<StdlibCollectionUnittest.MinimalBidirectionalCollection<StdlibCollectionUnittest.MinimalBidirectionalCollection<Swift.Int>>>.Index>
1922
RUN: swift-demangle -remangle-objc-rt '$ss23_ContiguousArrayStorageCys15FlattenSequenceVsE5IndexVy24StdlibCollectionUnittest020MinimalBidirectionalH0VyAIySiGG_GGD' | %FileCheck -check-prefix CHECK-GENERICEXT %s
2023

0 commit comments

Comments
 (0)