Skip to content

Commit

Permalink
Merge pull request #11009 from jckarter/unused-try-exit-block-4.0
Browse files Browse the repository at this point in the history
[4.0] SILGen: Remove unused catch block for a try? expr using SGF.eraseBasicBlock().
  • Loading branch information
jckarter committed Jul 18, 2017
2 parents c184647 + 31af652 commit dd684ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenExpr.cpp
Expand Up @@ -1212,7 +1212,7 @@ RValue RValueEmitter::visitOptionalTryExpr(OptionalTryExpr *E, SGFContext C) {
// If it turns out there are no uses of the catch block, just drop it.
if (catchBB->pred_empty()) {
// Remove the dead failureBB.
catchBB->eraseFromParent();
SGF.eraseBasicBlock(catchBB);

// The value we provide is the one we've already got.
if (!isByAddress)
Expand Down
9 changes: 9 additions & 0 deletions test/SILGen/errors.swift
Expand Up @@ -778,6 +778,15 @@ func testOptionalTry() {
_ = try? make_a_cat()
}

func sudo_make_a_cat() {}

// CHECK-LABEL: sil hidden @{{.*}}testOptionalTryThatNeverThrows
func testOptionalTryThatNeverThrows() {
guard let _ = try? sudo_make_a_cat() else { // expected-warning{{no calls to throwing}}
return
}
}

// CHECK-LABEL: sil hidden @_T06errors18testOptionalTryVaryyF
// CHECK-NEXT: bb0:
// CHECK-NEXT: [[BOX:%.+]] = alloc_box ${ var Optional<Cat> }
Expand Down

0 comments on commit dd684ea

Please sign in to comment.