r202200 - Hoist culling of -Wunreachable-code from headers before we even run the analysis.

Ted Kremenek kremenek at apple.com
Tue Feb 25 14:35:37 PST 2014


Author: kremenek
Date: Tue Feb 25 16:35:37 2014
New Revision: 202200

URL: http://llvm.org/viewvc/llvm-project?rev=202200&view=rev
Log:
Hoist culling of -Wunreachable-code from headers before we even run the analysis.

Modified:
    cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=202200&r1=202199&r2=202200&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Tue Feb 25 16:35:37 2014
@@ -66,12 +66,6 @@ namespace {
     UnreachableCodeHandler(Sema &s) : S(s) {}
 
     void HandleUnreachable(SourceLocation L, SourceRange R1, SourceRange R2) {
-      // As a heuristic prune all diagnostics not in the main file.  Currently
-      // the majority of warnings in headers are false positives.  These
-      // are largely caused by configuration state, e.g. preprocessor
-      // defined code, etc.
-      if (!S.getSourceManager().isInMainFile(L))
-        return;
       S.Diag(L, diag::warn_unreachable) << R1 << R2;
     }
   };
@@ -79,6 +73,16 @@ namespace {
 
 /// CheckUnreachable - Check for unreachable code.
 static void CheckUnreachable(Sema &S, AnalysisDeclContext &AC) {
+  // As a heuristic prune all diagnostics not in the main file.  Currently
+  // the majority of warnings in headers are false positives.  These
+  // are largely caused by configuration state, e.g. preprocessor
+  // defined code, etc.
+  //
+  // Note that this is also a performance optimization.  Analyzing
+  // headers many times can be expensive.
+  if (!S.getSourceManager().isInMainFile(AC.getDecl()->getLocStart()))
+    return;
+
   UnreachableCodeHandler UC(S);
   reachable_code::FindUnreachableCode(AC, UC);
 }





More information about the cfe-commits mailing list