Skip to content

SILGen: Don't call _diagnoseUnavailableCodeReached() from already unreachable functions #68874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/SILGen/SILGenApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5974,6 +5974,13 @@ RValue SILGenFunction::emitApplyOfLibraryIntrinsic(SILLocation loc,
}

void SILGenFunction::emitApplyOfUnavailableCodeReached() {
// Avoid attempting to insert a call if we don't have a valid insertion point.
// The insertion point could be invalid in, for instance, a function that
// takes uninhabited parameters and has therefore already has an unreachable
// instruction.
if (!B.hasValidInsertionPoint())
return;

auto loc = RegularLocation::getAutoGeneratedLocation(F.getLocation());
FuncDecl *fd = getASTContext().getDiagnoseUnavailableCodeReached();

Expand Down
9 changes: 9 additions & 0 deletions test/SILGen/unavailable_decl_optimization_stub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@ public func unavailableThrowingFunc() throws {
// CHECK: } // end sil function '$s4Test9globalVarAA1SVvau'
@available(*, unavailable)
public var globalVar = S()

public enum Uninhabited {}

//
// CHECK-LABEL: sil{{.*}}@$s4Test28unavailableTakingUninhabitedyyAA0D0OF : $@convention(thin) (Uninhabited) -> () {
// CHECK: unreachable
// CHECK: } // end sil function '$s4Test28unavailableTakingUninhabitedyyAA0D0OF'
@available(*, unavailable)
public func unavailableTakingUninhabited(_ u: Uninhabited) {}