From 094bc31000279a139408e0a3a988010f5c5a918c Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 7 May 2009 19:02:53 +0000 Subject: [PATCH] Fix . When using -analyze, -Werror has no effect. llvm-svn: 71172 --- clang/test/Analysis/override-werror.c | 15 +++++++++++++++ clang/tools/clang-cc/AnalysisConsumer.cpp | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 clang/test/Analysis/override-werror.c diff --git a/clang/test/Analysis/override-werror.c b/clang/test/Analysis/override-werror.c new file mode 100644 index 000000000000..f928ee031fe3 --- /dev/null +++ b/clang/test/Analysis/override-werror.c @@ -0,0 +1,15 @@ +// RUN: clang-cc -analyze -checker-cfref -Werror %s -analyzer-store=basic -verify && +// RUN: clang-cc -analyze -checker-cfref -Werror %s -analyzer-store=region -verify + +// This test case illustrates that using '-analyze' overrides the effect of +// -Werror. This allows basic warnings not to interfere with producing +// analyzer results. + +char* f(int *p) { + return p; // expected-warning{{incompatible pointer types returning 'int *', expected 'char *'}} +} + +void g(int *p) { + if (!p) *p = 0; // expected-warning{{null}} +} + diff --git a/clang/tools/clang-cc/AnalysisConsumer.cpp b/clang/tools/clang-cc/AnalysisConsumer.cpp index b1fb7417825f..381b9d0ba2b8 100644 --- a/clang/tools/clang-cc/AnalysisConsumer.cpp +++ b/clang/tools/clang-cc/AnalysisConsumer.cpp @@ -654,6 +654,9 @@ ASTConsumer* clang::CreateAnalysisConsumer(Diagnostic &diags, Preprocessor* pp, #include "Analyses.def" default: break; } + + // Last, disable the effects of '-Werror' when using the AnalysisConsumer. + diags.setWarningsAsErrors(false); return C.take(); }