Skip to content

Commit 0e9bf63

Browse files
authored
Merge pull request #11008 from jckarter/unused-try-exit-block
SILGen: Remove unused catch block for a try? expr using SGF.eraseBasicBlock().
2 parents 3f2827f + 59b53c9 commit 0e9bf63

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ RValue RValueEmitter::visitOptionalTryExpr(OptionalTryExpr *E, SGFContext C) {
14261426
// If it turns out there are no uses of the catch block, just drop it.
14271427
if (catchBB->pred_empty()) {
14281428
// Remove the dead failureBB.
1429-
catchBB->eraseFromParent();
1429+
SGF.eraseBasicBlock(catchBB);
14301430

14311431
// The value we provide is the one we've already got.
14321432
if (!isByAddress)

test/SILGen/errors.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,15 @@ func testOptionalTry() {
778778
_ = try? make_a_cat()
779779
}
780780

781+
func sudo_make_a_cat() {}
782+
783+
// CHECK-LABEL: sil hidden @{{.*}}testOptionalTryThatNeverThrows
784+
func testOptionalTryThatNeverThrows() {
785+
guard let _ = try? sudo_make_a_cat() else { // expected-warning{{no calls to throwing}}
786+
return
787+
}
788+
}
789+
781790
// CHECK-LABEL: sil hidden @_T06errors18testOptionalTryVaryyF
782791
// CHECK-NEXT: bb0:
783792
// CHECK-NEXT: [[BOX:%.+]] = alloc_box ${ var Optional<Cat> }

0 commit comments

Comments
 (0)