summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
diff options
context:
space:
mode:
authorKeno Fischer <keno@alumni.harvard.edu>2019-06-07 23:34:00 +0000
committerKeno Fischer <keno@alumni.harvard.edu>2019-06-07 23:34:00 +0000
commit6f48c076207f49dde437d85dbd5e1bcdd580f973 (patch)
treec0a4a617f8ea560da59aa4e67e12e82192e8fb42 /clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
parenta59aeb3f29a97b685eb10005f8d2f70bd7d894ec (diff)
downloadbcm5719-llvm-6f48c076207f49dde437d85dbd5e1bcdd580f973.tar.gz
bcm5719-llvm-6f48c076207f49dde437d85dbd5e1bcdd580f973.zip
[analyzer] Add werror flag for analyzer warnings
Summary: We're using the clang static analyzer together with a number of custom analyses in our CI system to ensure that certain invariants are statiesfied for by the code every commit. Unfortunately, there currently doesn't seem to be a good way to determine whether any analyzer warnings were emitted, other than parsing clang's output (or using scan-build, which then in turn parses clang's output). As a simpler mechanism, simply add a `-analyzer-werror` flag to CC1 that causes the analyzer to emit its warnings as errors instead. I briefly tried to have this be `Werror=analyzer` and make it go through that machinery instead, but that seemed more trouble than it was worth in terms of conflicting with options to the actual build and special cases that would be required to circumvent the analyzers usual attempts to quiet non-analyzer warnings. This is simple and it works well. Reviewed-By: NoQ, Szelethusw Differential Revision: https://reviews.llvm.org/D62885 llvm-svn: 362855
Diffstat (limited to 'clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 5c674923e06..a75ff2563cf 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -83,10 +83,11 @@ void ento::createTextPathDiagnosticConsumer(AnalyzerOptions &AnalyzerOpts,
namespace {
class ClangDiagPathDiagConsumer : public PathDiagnosticConsumer {
DiagnosticsEngine &Diag;
- bool IncludePath;
+ bool IncludePath, ShouldEmitAsError;
+
public:
ClangDiagPathDiagConsumer(DiagnosticsEngine &Diag)
- : Diag(Diag), IncludePath(false) {}
+ : Diag(Diag), IncludePath(false), ShouldEmitAsError(false) {}
~ClangDiagPathDiagConsumer() override {}
StringRef getName() const override { return "ClangDiags"; }
@@ -101,9 +102,14 @@ public:
IncludePath = true;
}
+ void enableWerror() { ShouldEmitAsError = true; }
+
void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
FilesMade *filesMade) override {
- unsigned WarnID = Diag.getCustomDiagID(DiagnosticsEngine::Warning, "%0");
+ unsigned WarnID =
+ ShouldEmitAsError
+ ? Diag.getCustomDiagID(DiagnosticsEngine::Error, "%0")
+ : Diag.getCustomDiagID(DiagnosticsEngine::Warning, "%0");
unsigned NoteID = Diag.getCustomDiagID(DiagnosticsEngine::Note, "%0");
for (std::vector<const PathDiagnostic*>::iterator I = Diags.begin(),
@@ -225,6 +231,9 @@ public:
new ClangDiagPathDiagConsumer(PP.getDiagnostics());
PathConsumers.push_back(clangDiags);
+ if (Opts->AnalyzerWerror)
+ clangDiags->enableWerror();
+
if (Opts->AnalysisDiagOpt == PD_TEXT) {
clangDiags->enablePaths();
@@ -358,7 +367,7 @@ public:
return true;
llvm::Expected<const VarDecl *> CTUDeclOrError =
- CTU.getCrossTUDefinition(VD, Opts->CTUDir, Opts->CTUIndexName,
+ CTU.getCrossTUDefinition(VD, Opts->CTUDir, Opts->CTUIndexName,
Opts->DisplayCTUProgress);
if (!CTUDeclOrError) {
OpenPOWER on IntegriCloud