Skip to content

Commit 91bd3e6

Browse files
committed
SILGen: Check whether return statement has expression before examining for compatibility.
Avoid an assertion failure when a `return` with no expression appears inside of a noncopyable switch. Fixes rdar://127294417
1 parent 74ed041 commit 91bd3e6

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

lib/SILGen/SILGenPattern.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,19 +3374,21 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
33743374
if (auto ret = dyn_cast_or_null<ReturnStmt>(
33753375
caseLabel->getBody()->getSingleActiveElement()
33763376
.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+
}
33903392
}
33913393
}
33923394
}

0 commit comments

Comments
 (0)