Skip to content

Commit b8b8a20

Browse files
committed
[SILGen] Emit unreachable in emitProlog() for uninhabited arguments after other codegen
1 parent 8ca0f47 commit b8b8a20

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
@@ -555,19 +555,6 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
555555
capture, ++ArgNo);
556556
}
557557

558-
// Emit an unreachable instruction if a parameter type is
559-
// uninhabited
560-
if (paramList) {
561-
for (auto *param : *paramList) {
562-
if (param->getType()->isStructurallyUninhabited()) {
563-
SILLocation unreachableLoc(param);
564-
unreachableLoc.markAsPrologue();
565-
B.createUnreachable(unreachableLoc);
566-
break;
567-
}
568-
}
569-
}
570-
571558
// Whether the given declaration context is nested within an actor's
572559
// destructor.
573560
auto isInActorDestructor = [](DeclContext *dc) {
@@ -718,6 +705,21 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
718705
ExpectedExecutor);
719706
}
720707
}
708+
709+
// IMPORTANT: This block should be the last one in `emitProlog`,
710+
// since it terminates BB and no instructions should be insterted after it.
711+
// Emit an unreachable instruction if a parameter type is
712+
// uninhabited
713+
if (paramList) {
714+
for (auto *param : *paramList) {
715+
if (param->getType()->isStructurallyUninhabited()) {
716+
SILLocation unreachableLoc(param);
717+
unreachableLoc.markAsPrologue();
718+
B.createUnreachable(unreachableLoc);
719+
break;
720+
}
721+
}
722+
}
721723
}
722724

723725
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)