]> granicus.if.org Git - clang/commitdiff
Fix a bad interaction between -Wtautological-overlap-compare and delayed
authorRichard Trieu <rtrieu@google.com>
Tue, 15 Apr 2014 00:57:50 +0000 (00:57 +0000)
committerRichard Trieu <rtrieu@google.com>
Tue, 15 Apr 2014 00:57:50 +0000 (00:57 +0000)
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
lib/Sema/AnalysisBasedWarnings.cpp
test/Sema/warn-overlap.c

index c90d9479512f0051ed0226253abc3bcc49106d68..ef9ce56c9bded43f58cfdb58e5d2aa7548deb4c5 100644 (file)
@@ -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();
 }
index 32bdef6da92dabafac4259c6f96dcc43f7b33078..fc591bd77c5f1ce0512fb0bb23ec58642cc36081 100644 (file)
@@ -1838,12 +1838,12 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
       .setAlwaysAdd(Stmt::AttributedStmtClass);
   }
 
+  // Install the logical handler for -Wtautological-overlap-compare
+  std::unique_ptr<LogicalErrorHandler> 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;
index c98547153c609bc4b600ff61da5307bb7648561a..44d6ad5efa5edbc6b4bff431696d329e7a1aa800 100644 (file)
@@ -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;
+}