]> granicus.if.org Git - clang/commitdiff
Experiment with making -Wunreachable-code more immediately useful by restricting...
authorTed Kremenek <kremenek@apple.com>
Tue, 18 Feb 2014 22:12:10 +0000 (22:12 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 18 Feb 2014 22:12:10 +0000 (22:12 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201607 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/AnalysisBasedWarnings.cpp

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