@@ -627,12 +627,10 @@ struct CheckFallThroughDiagnostics {
627627static void CheckFallThroughForBody (Sema &S, const Decl *D, const Stmt *Body,
628628 QualType BlockType,
629629 const CheckFallThroughDiagnostics &CD,
630- AnalysisDeclContext &AC,
631- sema::FunctionScopeInfo *FSI) {
630+ AnalysisDeclContext &AC) {
632631
633632 bool ReturnsVoid = false ;
634633 bool HasNoReturn = false ;
635- bool IsCoroutine = FSI->isCoroutine ();
636634
637635 if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
638636 if (const auto *CBody = dyn_cast<CoroutineBodyStmt>(Body))
@@ -661,35 +659,27 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
661659 if (CD.checkDiagnostics (Diags, ReturnsVoid, HasNoReturn))
662660 return ;
663661 SourceLocation LBrace = Body->getBeginLoc (), RBrace = Body->getEndLoc ();
664- auto EmitDiag = [&](SourceLocation Loc, unsigned DiagID, unsigned FunMode) {
665- if (IsCoroutine) {
666- if (DiagID != 0 )
667- S.Diag (Loc, DiagID) << FSI->CoroutinePromise ->getType ();
668- } else {
669- S.Diag (Loc, DiagID) << FunMode;
670- }
671- };
672662
673663 // cpu_dispatch functions permit empty function bodies for ICC compatibility.
674664 if (D->getAsFunction () && D->getAsFunction ()->isCPUDispatchMultiVersion ())
675665 return ;
676666
677667 // Either in a function body compound statement, or a function-try-block.
678- switch (CheckFallThrough (AC)) {
668+ int FallThroughType = CheckFallThrough (AC);
669+ switch (FallThroughType) {
679670 case UnknownFallThrough:
680671 break ;
681672
682673 case MaybeFallThrough:
683- if (HasNoReturn)
684- EmitDiag (RBrace, CD.diag_FallThrough_HasNoReturn , CD.FunMode );
685- else if (!ReturnsVoid)
686- S.Diag (RBrace, CD.diag_FallThrough_ReturnsNonVoid ) << CD.FunMode << 1 ;
687- break ;
688674 case AlwaysFallThrough:
689- if (HasNoReturn)
690- EmitDiag (RBrace, CD.diag_FallThrough_HasNoReturn , CD.FunMode );
691- else if (!ReturnsVoid)
692- S.Diag (RBrace, CD.diag_FallThrough_ReturnsNonVoid ) << CD.FunMode << 0 ;
675+ if (HasNoReturn && CD.diag_FallThrough_HasNoReturn != 0 ) {
676+ S.Diag (RBrace, CD.diag_FallThrough_HasNoReturn ) << CD.FunMode ;
677+ } else if (!ReturnsVoid && CD.diag_FallThrough_ReturnsNonVoid != 0 ) {
678+ unsigned NotInAllControlPath =
679+ FallThroughType == MaybeFallThrough ? 1 : 0 ;
680+ S.Diag (RBrace, CD.diag_FallThrough_ReturnsNonVoid )
681+ << CD.FunMode << NotInAllControlPath;
682+ }
693683 break ;
694684 case NeverFallThroughOrReturn:
695685 if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn ) {
@@ -2730,7 +2720,7 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
27302720 : (fscope->isCoroutine ()
27312721 ? CheckFallThroughDiagnostics::MakeForCoroutine (D)
27322722 : CheckFallThroughDiagnostics::MakeForFunction (D)));
2733- CheckFallThroughForBody (S, D, Body, BlockType, CD, AC, fscope );
2723+ CheckFallThroughForBody (S, D, Body, BlockType, CD, AC);
27342724 }
27352725
27362726 // Warning: check for unreachable code
0 commit comments