@@ -2734,53 +2734,36 @@ static void flushDiagnostics(Sema &S, const sema::FunctionScopeInfo *fscope) {
27342734 S.Diag (D.Loc , D.PD );
27352735}
27362736
2737- void sema::AnalysisBasedWarnings::FlushDiagnostics (
2738- const SmallVector<clang::sema::PossiblyUnreachableDiag, 4 > PUDs) {
2739- for (const auto &D : PUDs)
2740- S.Diag (D.Loc , D.PD );
2741- }
2742-
27432737void sema::AnalysisBasedWarnings::EmitPossiblyUnreachableDiags (
27442738 AnalysisDeclContext &AC,
27452739 SmallVector<clang::sema::PossiblyUnreachableDiag, 4 > PUDs) {
27462740
2747- if (PUDs.empty ()) {
2741+ if (PUDs.empty ())
27482742 return ;
2749- }
2750-
2751- bool Analyzed = false ;
27522743
27532744 for (const auto &D : PUDs) {
27542745 for (const Stmt *S : D.Stmts )
27552746 AC.registerForcedBlockExpression (S);
27562747 }
27572748
27582749 if (AC.getCFG ()) {
2759- Analyzed = true ;
27602750 for (const auto &D : PUDs) {
2761- bool AllReachable = true ;
2762- for (const Stmt *St : D.Stmts ) {
2763- const CFGBlock *block = AC.getBlockForRegisteredExpression (St);
2764- CFGReverseBlockReachabilityAnalysis *cra =
2765- AC.getCFGReachablityAnalysis ();
2766- if (block && cra) {
2767- // Can this block be reached from the entrance?
2768- if (!cra->isReachable (&AC.getCFG ()->getEntry (), block)) {
2769- AllReachable = false ;
2770- break ;
2771- }
2772- }
2773- // If we cannot map to a basic block, assume the statement is
2774- // reachable.
2775- }
2776-
2777- if (AllReachable)
2751+ if (llvm::all_of (D.Stmts , [&](const Stmt *St) {
2752+ const CFGBlock *Block = AC.getBlockForRegisteredExpression (St);
2753+ CFGReverseBlockReachabilityAnalysis *Analysis =
2754+ AC.getCFGReachablityAnalysis ();
2755+ if (Block && Analysis)
2756+ if (!Analysis->isReachable (&AC.getCFG ()->getEntry (), Block))
2757+ return false ;
2758+ return true ;
2759+ })) {
27782760 S.Diag (D.Loc , D.PD );
2761+ }
27792762 }
2763+ } else {
2764+ for (const auto &D : PUDs)
2765+ S.Diag (D.Loc , D.PD );
27802766 }
2781-
2782- if (!Analyzed)
2783- FlushDiagnostics (PUDs);
27842767}
27852768
27862769void sema::AnalysisBasedWarnings::RegisterVarDeclWarning (
@@ -2790,12 +2773,10 @@ void sema::AnalysisBasedWarnings::RegisterVarDeclWarning(
27902773
27912774void sema::AnalysisBasedWarnings::IssueWarningsForRegisteredVarDecl (
27922775 VarDecl *VD) {
2793- if (VarDeclPossiblyUnreachableDiags.find (VD) ==
2794- VarDeclPossiblyUnreachableDiags.end ()) {
2776+ if (!llvm::is_contained (VarDeclPossiblyUnreachableDiags, VD))
27952777 return ;
2796- }
27972778
2798- AnalysisDeclContext AC (nullptr , VD);
2779+ AnalysisDeclContext AC (/* Mgr= */ nullptr , VD);
27992780
28002781 AC.getCFGBuildOptions ().PruneTriviallyFalseEdges = true ;
28012782 AC.getCFGBuildOptions ().AddEHEdges = false ;
0 commit comments