r201607 - Experiment with making -Wunreachable-code more immediately useful by restricting warnings to those issued in the main file.
Ted Kremenek
kremenek at apple.com
Tue Feb 18 14:12:10 PST 2014
Author: kremenek
Date: Tue Feb 18 16:12:10 2014
New Revision: 201607
URL: http://llvm.org/viewvc/llvm-project?rev=201607&view=rev
Log:
Experiment with making -Wunreachable-code more immediately useful by restricting warnings to those issued in the main file.
This warning has a whole bunch of known false positives, much of them due
to code that is "sometimes unreachable". This can caused by code that
is conditionally generated by the preprocessor, branches that are defined
in terms of architecture-specific details (e.g., the size of a type), and
so on. While these are all good things to address one by one, the reality
is that this warning has received little love lately. By restricting
its purvue, we can focus on the top issues effecting main files, which
should be smaller, and then gradually widen the scope.
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=201607&r1=201606&r2=201607&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Tue Feb 18 16:12:10 2014
@@ -66,6 +66,12 @@ 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;
}
};
More information about the cfe-commits
mailing list