Skip to content

Commit 35db37f

Browse files
committed
[Demangler] Fix OldRemangler to cope with Type nodes in a couple of places.
The Demangler can wrap types in a Node::Kind::Type node; these need to be handled by following the node's first child pointer. Failing to do this led to a crash or assertion failure in some cases. rdar://63678171
1 parent 775bff0 commit 35db37f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/Demangling/OldRemangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,9 @@ void Remangler::mangleAnyNominalType(Node *node, EntityContext &ctx) {
18231823
}
18241824

18251825
switch (node->getKind()) {
1826+
case Node::Kind::Type:
1827+
mangleAnyNominalType(node->getChild(0), ctx);
1828+
break;
18261829
case Node::Kind::OtherNominalType:
18271830
// Mangle unknown type kinds as structures since we can't change the old
18281831
// mangling. Give the mangling an artificial "private discriminator" so that
@@ -1866,6 +1869,9 @@ void Remangler::mangleOtherNominalType(Node *node, EntityContext &ctx) {
18661869
void Remangler::mangleNominalType(Node *node, char kind, EntityContext &ctx,
18671870
StringRef artificialPrivateDiscriminator) {
18681871
SubstitutionEntry entry;
1872+
if (node->getKind() == Node::Kind::Type) {
1873+
node = node->getChild(0);
1874+
}
18691875
if (trySubstitution(node, entry)) return;
18701876
mangleNamedEntity(node, kind, "", ctx, artificialPrivateDiscriminator);
18711877
addSubstitution(entry);

test/Demangle/remangle.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ RUN: diff %t.input %t.output
99
// CHECK: Swift.(Mystruct in _7B40D7ED6632C2BEA2CA3BFFD57E3435)
1010
RUN: swift-demangle -remangle-objc-rt '$ss8Mystruct33_7B40D7ED6632C2BEA2CA3BFFD57E3435LLV' | %FileCheck %s
1111

12+
// CHECK-OLD2: Swift.Int.related decl 'B' for protocol self-conformance descriptor for Swift.IteratorProtocol
13+
RUN: swift-demangle -remangle-objc-rt '$sSiStMSLB_p' | %FileCheck -check-prefix CHECK-OLD2 %s
14+
1215
// CHECK-GENERICEXT: Swift._ContiguousArrayStorage<(extension in Swift):Swift.FlattenSequence<StdlibCollectionUnittest.MinimalBidirectionalCollection<StdlibCollectionUnittest.MinimalBidirectionalCollection<Swift.Int>>>.Index>
1316
RUN: swift-demangle -remangle-objc-rt '$ss23_ContiguousArrayStorageCys15FlattenSequenceVsE5IndexVy24StdlibCollectionUnittest020MinimalBidirectionalH0VyAIySiGG_GGD' | %FileCheck -check-prefix CHECK-GENERICEXT %s
1417

0 commit comments

Comments
 (0)