@@ -627,12 +627,10 @@ struct CheckFallThroughDiagnostics {
627
627
static void CheckFallThroughForBody (Sema &S, const Decl *D, const Stmt *Body,
628
628
QualType BlockType,
629
629
const CheckFallThroughDiagnostics &CD,
630
- AnalysisDeclContext &AC,
631
- sema::FunctionScopeInfo *FSI) {
630
+ AnalysisDeclContext &AC) {
632
631
633
632
bool ReturnsVoid = false ;
634
633
bool HasNoReturn = false ;
635
- bool IsCoroutine = FSI->isCoroutine ();
636
634
637
635
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
638
636
if (const auto *CBody = dyn_cast<CoroutineBodyStmt>(Body))
@@ -661,35 +659,27 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
661
659
if (CD.checkDiagnostics (Diags, ReturnsVoid, HasNoReturn))
662
660
return ;
663
661
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
- };
672
662
673
663
// cpu_dispatch functions permit empty function bodies for ICC compatibility.
674
664
if (D->getAsFunction () && D->getAsFunction ()->isCPUDispatchMultiVersion ())
675
665
return ;
676
666
677
667
// Either in a function body compound statement, or a function-try-block.
678
- switch (CheckFallThrough (AC)) {
668
+ int FallThroughType = CheckFallThrough (AC);
669
+ switch (FallThroughType) {
679
670
case UnknownFallThrough:
680
671
break ;
681
672
682
673
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 ;
688
674
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
+ }
693
683
break ;
694
684
case NeverFallThroughOrReturn:
695
685
if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn ) {
@@ -2730,7 +2720,7 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
2730
2720
: (fscope->isCoroutine ()
2731
2721
? CheckFallThroughDiagnostics::MakeForCoroutine (D)
2732
2722
: CheckFallThroughDiagnostics::MakeForFunction (D)));
2733
- CheckFallThroughForBody (S, D, Body, BlockType, CD, AC, fscope );
2723
+ CheckFallThroughForBody (S, D, Body, BlockType, CD, AC);
2734
2724
}
2735
2725
2736
2726
// Warning: check for unreachable code
0 commit comments