]> granicus.if.org Git - clang/commitdiff
Hoist culling of -Wunreachable-code from headers before we even run the analysis.
authorTed Kremenek <kremenek@apple.com>
Tue, 25 Feb 2014 22:35:37 +0000 (22:35 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 25 Feb 2014 22:35:37 +0000 (22:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202200 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/AnalysisBasedWarnings.cpp

index f1b25753abff4d13cfd8654b64036a20551be32d..099ef253736c878f93afd4854d70c3d59b63a07a 100644 (file)
@@ -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);
 }