@@ -2724,53 +2724,36 @@ static void flushDiagnostics(Sema &S, const sema::FunctionScopeInfo *fscope) {
27242724 S.Diag (D.Loc , D.PD );
27252725}
27262726
2727- void sema::AnalysisBasedWarnings::FlushDiagnostics (
2728- const SmallVector<clang::sema::PossiblyUnreachableDiag, 4 > PUDs) {
2729- for (const auto &D : PUDs)
2730- S.Diag (D.Loc , D.PD );
2731- }
2732-
27332727void sema::AnalysisBasedWarnings::EmitPossiblyUnreachableDiags (
27342728 AnalysisDeclContext &AC,
27352729 SmallVector<clang::sema::PossiblyUnreachableDiag, 4 > PUDs) {
27362730
2737- if (PUDs.empty ()) {
2731+ if (PUDs.empty ())
27382732 return ;
2739- }
2740-
2741- bool Analyzed = false ;
27422733
27432734 for (const auto &D : PUDs) {
27442735 for (const Stmt *S : D.Stmts )
27452736 AC.registerForcedBlockExpression (S);
27462737 }
27472738
27482739 if (AC.getCFG ()) {
2749- Analyzed = true ;
27502740 for (const auto &D : PUDs) {
2751- bool AllReachable = true ;
2752- for (const Stmt *St : D.Stmts ) {
2753- const CFGBlock *block = AC.getBlockForRegisteredExpression (St);
2754- CFGReverseBlockReachabilityAnalysis *cra =
2755- AC.getCFGReachablityAnalysis ();
2756- if (block && cra) {
2757- // Can this block be reached from the entrance?
2758- if (!cra->isReachable (&AC.getCFG ()->getEntry (), block)) {
2759- AllReachable = false ;
2760- break ;
2761- }
2762- }
2763- // If we cannot map to a basic block, assume the statement is
2764- // reachable.
2765- }
2766-
2767- if (AllReachable)
2741+ if (llvm::all_of (D.Stmts , [&](const Stmt *St) {
2742+ const CFGBlock *Block = AC.getBlockForRegisteredExpression (St);
2743+ CFGReverseBlockReachabilityAnalysis *Analysis =
2744+ AC.getCFGReachablityAnalysis ();
2745+ if (Block && Analysis)
2746+ if (!Analysis->isReachable (&AC.getCFG ()->getEntry (), Block))
2747+ return false ;
2748+ return true ;
2749+ })) {
27682750 S.Diag (D.Loc , D.PD );
2751+ }
27692752 }
2753+ } else {
2754+ for (const auto &D : PUDs)
2755+ S.Diag (D.Loc , D.PD );
27702756 }
2771-
2772- if (!Analyzed)
2773- FlushDiagnostics (PUDs);
27742757}
27752758
27762759void sema::AnalysisBasedWarnings::RegisterVarDeclWarning (
@@ -2780,12 +2763,10 @@ void sema::AnalysisBasedWarnings::RegisterVarDeclWarning(
27802763
27812764void sema::AnalysisBasedWarnings::IssueWarningsForRegisteredVarDecl (
27822765 VarDecl *VD) {
2783- if (VarDeclPossiblyUnreachableDiags.find (VD) ==
2784- VarDeclPossiblyUnreachableDiags.end ()) {
2766+ if (!llvm::is_contained (VarDeclPossiblyUnreachableDiags, VD))
27852767 return ;
2786- }
27872768
2788- AnalysisDeclContext AC (nullptr , VD);
2769+ AnalysisDeclContext AC (/* Mgr= */ nullptr , VD);
27892770
27902771 AC.getCFGBuildOptions ().PruneTriviallyFalseEdges = true ;
27912772 AC.getCFGBuildOptions ().AddEHEdges = false ;
0 commit comments