Skip to content

Commit 5ef85ff

Browse files
committed
SILGen: Don't call _diagnoseUnavailableCodeReached() from already unreachable functions.
We must avoid emitting applies of `_diagnoseUnavailableCodeReached()` in function bodies that are already marked unreachable since there isn't a valid insertion point once an `unreachable` instruction has been emitted. A function body may be marked unreachable if, for example, the parameters of the function are uninhabited. Resolves rdar://116246677
1 parent 8edf870 commit 5ef85ff

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5974,6 +5974,13 @@ RValue SILGenFunction::emitApplyOfLibraryIntrinsic(SILLocation loc,
59745974
}
59755975

59765976
void SILGenFunction::emitApplyOfUnavailableCodeReached() {
5977+
// Avoid attempting to insert a call if we don't have a valid insertion point.
5978+
// The insertion point could be invalid in, for instance, a function that
5979+
// takes uninhabited parameters and has therefore already has an unreachable
5980+
// instruction.
5981+
if (!B.hasValidInsertionPoint())
5982+
return;
5983+
59775984
auto loc = RegularLocation::getAutoGeneratedLocation(F.getLocation());
59785985
FuncDecl *fd = getASTContext().getDiagnoseUnavailableCodeReached();
59795986

test/SILGen/unavailable_decl_optimization_stub.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,12 @@ public func unavailableThrowingFunc() throws {
3939
// CHECK: } // end sil function '$s4Test9globalVarAA1SVvau'
4040
@available(*, unavailable)
4141
public var globalVar = S()
42+
43+
public enum Uninhabited {}
44+
45+
//
46+
// CHECK-LABEL: sil{{.*}}@$s4Test28unavailableTakingUninhabitedyyAA0D0OF : $@convention(thin) (Uninhabited) -> () {
47+
// CHECK: unreachable
48+
// CHECK: } // end sil function '$s4Test28unavailableTakingUninhabitedyyAA0D0OF'
49+
@available(*, unavailable)
50+
public func unavailableTakingUninhabited(_ u: Uninhabited) {}

0 commit comments

Comments
 (0)