Skip to content

Commit ad99f5c

Browse files
authored
Merge pull request #39106 from al45tair/problem/82252704-5.5
[Demangler] Fix incorrect assertions in OldRemangler and NodePrinter.
2 parents d20318b + 28cf05a commit ad99f5c

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
@@ -772,7 +772,7 @@ class NodePrinter {
772772
}
773773

774774
void printFunctionType(NodePointer LabelList, NodePointer node) {
775-
if (node->getNumChildren() < 2 || node->getNumChildren() > 6) {
775+
if (node->getNumChildren() < 2) {
776776
setInvalid();
777777
return;
778778
}
@@ -811,9 +811,14 @@ class NodePrinter {
811811
assert(false && "Unhandled function type in printFunctionType!");
812812
}
813813

814+
unsigned argIndex = node->getNumChildren() - 2;
814815
unsigned startIndex = 0;
815816
bool isSendable = false, isAsync = false, isThrows = false;
816817
auto diffKind = MangledDifferentiabilityKind::NonDifferentiable;
818+
if (node->getChild(startIndex)->getKind() == Node::Kind::ClangType) {
819+
// handled earlier
820+
++startIndex;
821+
}
817822
if (node->getChild(startIndex)->getKind() ==
818823
Node::Kind::GlobalActorFunctionType) {
819824
print(node->getChild(startIndex));
@@ -825,10 +830,6 @@ class NodePrinter {
825830
(MangledDifferentiabilityKind)node->getChild(startIndex)->getIndex();
826831
++startIndex;
827832
}
828-
if (node->getChild(startIndex)->getKind() == Node::Kind::ClangType) {
829-
// handled earlier
830-
++startIndex;
831-
}
832833
if (node->getChild(startIndex)->getKind() == Node::Kind::ThrowsAnnotation) {
833834
++startIndex;
834835
isThrows = true;
@@ -863,7 +864,7 @@ class NodePrinter {
863864
if (isSendable)
864865
Printer << "@Sendable ";
865866

866-
printFunctionParameters(LabelList, node->getChild(startIndex),
867+
printFunctionParameters(LabelList, node->getChild(argIndex),
867868
Options.ShowFunctionArgumentTypes);
868869

869870
if (!Options.ShowFunctionArgumentTypes)
@@ -875,7 +876,7 @@ class NodePrinter {
875876
if (isThrows)
876877
Printer << " throws";
877878

878-
print(node->getChild(startIndex + 1));
879+
print(node->getChild(argIndex + 1));
879880
}
880881

881882
void printImplFunctionType(NodePointer fn) {

lib/Demangling/OldRemangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,8 +1098,8 @@ void Remangler::mangleEntityType(Node *node, EntityContext &ctx) {
10981098
node->getKind() == Node::Kind::NoEscapeFunctionType)
10991099
? 'F'
11001100
: 'f');
1101+
assert(node->getNumChildren() >= 2);
11011102
unsigned inputIndex = node->getNumChildren() - 2;
1102-
assert(inputIndex <= 1);
11031103
for (unsigned i = 0; i <= inputIndex; ++i)
11041104
mangle(node->begin()[i]);
11051105
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)