Skip to content

Commit 0c48517

Browse files
authored
Merge pull request #60167 from maxovtsin/fix-crash-uninhabited-param-closure-executor
[SILGen] Emit unreachable in emitProlog() for uninhabited arguments after other codegen
2 parents 5b171ce + b8b8a20 commit 0c48517

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -591,19 +591,6 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
591591
capture, ++ArgNo);
592592
}
593593

594-
// Emit an unreachable instruction if a parameter type is
595-
// uninhabited
596-
if (paramList) {
597-
for (auto *param : *paramList) {
598-
if (param->getType()->isStructurallyUninhabited()) {
599-
SILLocation unreachableLoc(param);
600-
unreachableLoc.markAsPrologue();
601-
B.createUnreachable(unreachableLoc);
602-
break;
603-
}
604-
}
605-
}
606-
607594
// Whether the given declaration context is nested within an actor's
608595
// destructor.
609596
auto isInActorDestructor = [](DeclContext *dc) {
@@ -754,6 +741,21 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
754741
ExpectedExecutor);
755742
}
756743
}
744+
745+
// IMPORTANT: This block should be the last one in `emitProlog`,
746+
// since it terminates BB and no instructions should be insterted after it.
747+
// Emit an unreachable instruction if a parameter type is
748+
// uninhabited
749+
if (paramList) {
750+
for (auto *param : *paramList) {
751+
if (param->getType()->isStructurallyUninhabited()) {
752+
SILLocation unreachableLoc(param);
753+
unreachableLoc.markAsPrologue();
754+
B.createUnreachable(unreachableLoc);
755+
break;
756+
}
757+
}
758+
}
757759
}
758760

759761
SILValue SILGenFunction::emitMainExecutor(SILLocation loc) {

test/SILGen/functions_uninhabited_param.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-emit-sil %s -o /dev/null -verify
2+
// RUN: %target-swift-emit-sil %s -o /dev/null -verify -enable-actor-data-race-checks
23

34
//===--- Function declaration with uninhabited parameter type
45

@@ -19,11 +20,16 @@ map { arg in // expected-note {{'arg' is of type 'Never' which cannot be constru
1920
return 5 // expected-warning {{will never be executed}}
2021
}
2122

22-
// We used to crash when emitting the closure below.
23+
// We used to crash when emitting the closures below.
2324
enum E {
2425
static func f(_: E) {}
2526
}
2627

28+
@MainActor
29+
class Bar {
30+
var foo: (E) -> Void = { _ in }
31+
}
32+
2733
let _: (E.Type) -> (E) -> () = { s in { e in s.f(e) } }
2834
// expected-warning@-1 {{will never be executed}}
2935
// expected-note@-2 {{'e' is of type 'E' which cannot be constructed because it is an enum with no cases}}

0 commit comments

Comments
 (0)