diff --git a/lib/SILGen/SILGenExpr.cpp b/lib/SILGen/SILGenExpr.cpp index a262619b2e0e8..e9e41c38c6177 100644 --- a/lib/SILGen/SILGenExpr.cpp +++ b/lib/SILGen/SILGenExpr.cpp @@ -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) diff --git a/test/SILGen/errors.swift b/test/SILGen/errors.swift index 899227158b383..52e0baf2c6125 100644 --- a/test/SILGen/errors.swift +++ b/test/SILGen/errors.swift @@ -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 }