From d0abc5054daa533f3031e08eccd959a70b75551e Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Tue, 15 Apr 2014 00:57:50 +0000 Subject: [PATCH] Fix a bad interaction between -Wtautological-overlap-compare and delayed diagnostics which caused delayed diagnostics on dead paths to be emitted. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206232 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/AnalysisDeclContext.cpp | 6 ++++++ lib/Sema/AnalysisBasedWarnings.cpp | 15 +++++++++++---- test/Sema/warn-overlap.c | 6 ++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/Analysis/AnalysisDeclContext.cpp b/lib/Analysis/AnalysisDeclContext.cpp index c90d947951..ef9ce56c9b 100644 --- a/lib/Analysis/AnalysisDeclContext.cpp +++ b/lib/Analysis/AnalysisDeclContext.cpp @@ -189,6 +189,9 @@ CFG *AnalysisDeclContext::getCFG() { if (PM) addParentsForSyntheticStmts(cfg.get(), *PM); + + // The Obersver should only observe one build of the CFG. + getCFGBuildOptions().Observer = 0; } return cfg.get(); } @@ -205,6 +208,9 @@ CFG *AnalysisDeclContext::getUnoptimizedCFG() { if (PM) addParentsForSyntheticStmts(completeCFG.get(), *PM); + + // The Obersver should only observe one build of the CFG. + getCFGBuildOptions().Observer = 0; } return completeCFG.get(); } diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 32bdef6da9..fc591bd77c 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -1838,12 +1838,12 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, .setAlwaysAdd(Stmt::AttributedStmtClass); } + // Install the logical handler for -Wtautological-overlap-compare + std::unique_ptr LEH; if (Diags.getDiagnosticLevel(diag::warn_tautological_overlap_comparison, D->getLocStart())) { - LogicalErrorHandler LEH(S); - AC.getCFGBuildOptions().Observer = &LEH; - AC.getCFG(); - AC.getCFGBuildOptions().Observer = 0; + LEH.reset(new LogicalErrorHandler(S)); + AC.getCFGBuildOptions().Observer = LEH.get(); } // Emit delayed diagnostics. @@ -1991,6 +1991,13 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, } } + // If none of the previous checks caused a CFG build, trigger one here + // for -Wtautological-overlap-compare + if (Diags.getDiagnosticLevel(diag::warn_tautological_overlap_comparison, + D->getLocStart())) { + AC.getCFG(); + } + // Collect statistics about the CFG if it was built. if (S.CollectStats && AC.isCFGBuilt()) { ++NumFunctionsAnalyzed; diff --git a/test/Sema/warn-overlap.c b/test/Sema/warn-overlap.c index c98547153c..44d6ad5efa 100644 --- a/test/Sema/warn-overlap.c +++ b/test/Sema/warn-overlap.c @@ -56,3 +56,9 @@ void f(int x) { if (x == (mydefine + 1) && x > 3) { } } +// Don't generate a warning here. +void array_out_of_bounds() { + int x; + int buffer[4]; + x = (-7 > 0) ? (buffer[-7]) : 0; +} -- 2.40.0