From 3a3f306a65e7a5fd92b5621c829dcb642c5c4c51 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 25 Feb 2014 22:35:37 +0000 Subject: [PATCH] Hoist culling of -Wunreachable-code from headers before we even run the analysis. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202200 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/AnalysisBasedWarnings.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index f1b25753ab..099ef25373 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -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); } -- 2.40.0