@@ -3374,19 +3374,21 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
3374
3374
if (auto ret = dyn_cast_or_null<ReturnStmt>(
3375
3375
caseLabel->getBody ()->getSingleActiveElement ()
3376
3376
.dyn_cast <Stmt*>())) {
3377
- Expr *result = ret->getResult ()->getSemanticsProvidingExpr ();
3378
- if (result->getType ()->isNoncopyable ()) {
3379
- while (auto conv = dyn_cast<ImplicitConversionExpr>(result)) {
3380
- result = conv->getSubExpr ()->getSemanticsProvidingExpr ();
3381
- }
3382
- if (auto dr = dyn_cast<DeclRefExpr>(result)) {
3383
- if (std::find (caseLabel->getCaseBodyVariables ().begin (),
3384
- caseLabel->getCaseBodyVariables ().end (),
3385
- dr->getDecl ())
3386
- != caseLabel->getCaseBodyVariables ().end ()) {
3387
- SGM.diagnose (result->getLoc (),
3388
- diag::return_borrowing_switch_binding);
3389
- ownership = ValueOwnership::Owned;
3377
+ if (ret->hasResult ()) {
3378
+ Expr *result = ret->getResult ()->getSemanticsProvidingExpr ();
3379
+ if (result->getType ()->isNoncopyable ()) {
3380
+ while (auto conv = dyn_cast<ImplicitConversionExpr>(result)) {
3381
+ result = conv->getSubExpr ()->getSemanticsProvidingExpr ();
3382
+ }
3383
+ if (auto dr = dyn_cast<DeclRefExpr>(result)) {
3384
+ if (std::find (caseLabel->getCaseBodyVariables ().begin (),
3385
+ caseLabel->getCaseBodyVariables ().end (),
3386
+ dr->getDecl ())
3387
+ != caseLabel->getCaseBodyVariables ().end ()) {
3388
+ SGM.diagnose (result->getLoc (),
3389
+ diag::return_borrowing_switch_binding);
3390
+ ownership = ValueOwnership::Owned;
3391
+ }
3390
3392
}
3391
3393
}
3392
3394
}
0 commit comments