Skip to content

Commit ce7358d

Browse files
committed
SIL: create hop_to_executor instructions with "auto-generated" debug locations.
Those instructions should not be "visible" for debugging and for diagnostic messages. Fixes a wrong "unreachable code" warning. https://bugs.swift.org/browse/SR-14873 rdar://80237870
1 parent 6d5b0c7 commit ce7358d

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

include/swift/SIL/SILLocation.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,13 @@ class SILLocation {
333333
/// Marks the location as coming from auto-generated body.
334334
void markAutoGenerated() { kindAndFlags.fields.autoGenerated = true; }
335335

336+
/// Returns this location with the auto-generated flag set.
337+
SILLocation asAutoGenerated() const {
338+
SILLocation loc = *this;
339+
loc.markAutoGenerated();
340+
return loc;
341+
}
342+
336343
/// Returns true if the location represents an artificially generated
337344
/// body, such as thunks or default destructors.
338345
///

lib/SILGen/SILGenConstructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ void SILGenFunction::emitConstructorPrologActorHop(
677677

678678
if (auto executor = emitExecutor(loc, *maybeIso, None)) {
679679
ExpectedExecutor = *executor;
680-
B.createHopToExecutor(loc, *executor, /*mandatory*/ false);
680+
B.createHopToExecutor(loc.asAutoGenerated(), *executor, /*mandatory*/ false);
681681
}
682682
}
683683

lib/SILGen/SILGenProlog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ ExecutorBreadcrumb SILGenFunction::emitHopToTargetExecutor(
668668
// If we're calling from an actor method ourselves, then we'll want to hop
669669
// back to our own actor.
670670
auto breadcrumb = ExecutorBreadcrumb(emitGetCurrentExecutor(loc));
671-
B.createHopToExecutor(loc, executor, /*mandatory*/ false);
671+
B.createHopToExecutor(loc.asAutoGenerated(), executor, /*mandatory*/ false);
672672
return breadcrumb;
673673
}
674674

@@ -710,7 +710,7 @@ void SILGenFunction::emitHopToActorValue(SILLocation loc, ManagedValue actor) {
710710
"Builtin.hopToActor must be in an actor-independent function");
711711
}
712712
SILValue executor = emitLoadActorExecutor(loc, actor);
713-
B.createHopToExecutor(loc, executor, /*mandatory*/ true);
713+
B.createHopToExecutor(loc.asAutoGenerated(), executor, /*mandatory*/ true);
714714
}
715715

716716
void SILGenFunction::emitPreconditionCheckExpectedExecutor(
@@ -741,7 +741,7 @@ void SILGenFunction::emitPreconditionCheckExpectedExecutor(
741741

742742
void ExecutorBreadcrumb::emit(SILGenFunction &SGF, SILLocation loc) {
743743
if (Executor)
744-
SGF.B.createHopToExecutor(loc, Executor, /*mandatory*/ false);
744+
SGF.B.createHopToExecutor(loc.asAutoGenerated(), Executor, /*mandatory*/ false);
745745
}
746746

747747
SILValue SILGenFunction::emitGetCurrentExecutor(SILLocation loc) {

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ static void injectHopToExecutorAfter(SILLocation loc,
818818
if (needsBorrow)
819819
actor = b.createBeginBorrow(loc, actor);
820820

821-
b.createHopToExecutor(loc, actor, /*mandatory=*/false);
821+
b.createHopToExecutor(loc.asAutoGenerated(), actor, /*mandatory=*/false);
822822

823823
if (needsBorrow)
824824
b.createEndBorrow(loc, actor);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-frontend -disable-availability-checking -emit-sil -verify %s
2+
3+
// REQUIRES: concurrency
4+
5+
// Check that the inserted hop-to-executor instructions don't cause a false
6+
// "unreachable code" warning.
7+
8+
@MainActor
9+
func bye() -> Never {
10+
print("bye")
11+
fatalError()
12+
}
13+
14+
func testit() async {
15+
await bye()
16+
}
17+

0 commit comments

Comments
 (0)