@@ -529,15 +529,20 @@ static bool simplifyBlocksWithCallsToNoReturn(SILBasicBlock &BB,
529
529
// Diagnose the unreachable code within the same block as the call to
530
530
// noreturn.
531
531
if (isUserCode (CurrentInst) && !DiagnosedUnreachableCode) {
532
- if (NoReturnCall->getLoc ().is <RegularLocation>()) {
533
- if (!NoReturnCall->getLoc ().isASTNode <ExplicitCastExpr>()) {
534
- diagnose (BB.getModule ().getASTContext (),
535
- CurrentInst->getLoc ().getSourceLoc (),
536
- diag::unreachable_code);
537
- diagnose (BB.getModule ().getASTContext (),
538
- NoReturnCall->getLoc ().getSourceLoc (),
539
- diag::call_to_noreturn_note);
540
- DiagnosedUnreachableCode = true ;
532
+ // If we have an instruction that is an end_borrow, ignore it. This
533
+ // happens when passing a guaranteed argument through generic code paths
534
+ // to no return functions.
535
+ if (!isa<EndBorrowInst>(CurrentInst)) {
536
+ if (NoReturnCall->getLoc ().is <RegularLocation>()) {
537
+ if (!NoReturnCall->getLoc ().isASTNode <ExplicitCastExpr>()) {
538
+ diagnose (BB.getModule ().getASTContext (),
539
+ CurrentInst->getLoc ().getSourceLoc (),
540
+ diag::unreachable_code);
541
+ diagnose (BB.getModule ().getASTContext (),
542
+ NoReturnCall->getLoc ().getSourceLoc (),
543
+ diag::call_to_noreturn_note);
544
+ DiagnosedUnreachableCode = true ;
545
+ }
541
546
}
542
547
}
543
548
}
0 commit comments