Skip to content

Commit d9110de

Browse files
authored
Merge pull request swiftlang#39071 from al45tair/problem/82252704
[Demangler] Fix incorrect assertions in OldRemangler and NodePrinter.
2 parents d377749 + e6ced29 commit d9110de

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

lib/Demangling/NodePrinter.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ class NodePrinter {
775775

776776
void printFunctionType(NodePointer LabelList, NodePointer node,
777777
unsigned depth) {
778-
if (node->getNumChildren() < 2 || node->getNumChildren() > 6) {
778+
if (node->getNumChildren() < 2) {
779779
setInvalid();
780780
return;
781781
}
@@ -814,9 +814,14 @@ class NodePrinter {
814814
assert(false && "Unhandled function type in printFunctionType!");
815815
}
816816

817+
unsigned argIndex = node->getNumChildren() - 2;
817818
unsigned startIndex = 0;
818819
bool isSendable = false, isAsync = false, isThrows = false;
819820
auto diffKind = MangledDifferentiabilityKind::NonDifferentiable;
821+
if (node->getChild(startIndex)->getKind() == Node::Kind::ClangType) {
822+
// handled earlier
823+
++startIndex;
824+
}
820825
if (node->getChild(startIndex)->getKind() ==
821826
Node::Kind::GlobalActorFunctionType) {
822827
print(node->getChild(startIndex), depth + 1);
@@ -828,10 +833,6 @@ class NodePrinter {
828833
(MangledDifferentiabilityKind)node->getChild(startIndex)->getIndex();
829834
++startIndex;
830835
}
831-
if (node->getChild(startIndex)->getKind() == Node::Kind::ClangType) {
832-
// handled earlier
833-
++startIndex;
834-
}
835836
if (node->getChild(startIndex)->getKind() == Node::Kind::ThrowsAnnotation) {
836837
++startIndex;
837838
isThrows = true;
@@ -866,7 +867,7 @@ class NodePrinter {
866867
if (isSendable)
867868
Printer << "@Sendable ";
868869

869-
printFunctionParameters(LabelList, node->getChild(startIndex), depth,
870+
printFunctionParameters(LabelList, node->getChild(argIndex), depth,
870871
Options.ShowFunctionArgumentTypes);
871872

872873
if (!Options.ShowFunctionArgumentTypes)
@@ -878,7 +879,7 @@ class NodePrinter {
878879
if (isThrows)
879880
Printer << " throws";
880881

881-
print(node->getChild(startIndex + 1), depth + 1);
882+
print(node->getChild(argIndex + 1), depth + 1);
882883
}
883884

884885
void printImplFunctionType(NodePointer fn, unsigned depth) {

lib/Demangling/OldRemangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,8 +1206,8 @@ void Remangler::mangleEntityType(Node *node, EntityContext &ctx,
12061206
node->getKind() == Node::Kind::NoEscapeFunctionType)
12071207
? 'F'
12081208
: 'f');
1209+
assert(node->getNumChildren() >= 2);
12091210
unsigned inputIndex = node->getNumChildren() - 2;
1210-
assert(inputIndex <= 1);
12111211
for (unsigned i = 0; i <= inputIndex; ++i)
12121212
mangle(node->begin()[i], depth + 1);
12131213
auto returnType = node->begin()[inputIndex+1];

test/Demangle/rdar-82252704.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// rdar://82252704 - [SR-15070]: Declaring a class inside a async throws
2+
// function crashes compiler
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: %target-swift-frontend -c %s -o %t/test.o
6+
7+
@available(SwiftStdlib 5.5, *)
8+
func MyFunction() async throws {
9+
class MyClass {}
10+
}

0 commit comments

Comments
 (0)