From 8c80070de2c200e99f5b6d95a003ccbf5b1ca911 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 29 May 2008 15:36:45 +0000 Subject: [PATCH] Implement support for -w, which silences all warnings. PR2384. llvm-svn: 51683 --- clang/Driver/clang.cpp | 4 ++++ clang/include/clang/Basic/Diagnostic.h | 6 ++++++ clang/lib/Basic/Diagnostic.cpp | 13 +++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index 21f1eb4f68fb..714b03eca307 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -461,6 +461,9 @@ void InitializeGCMode(LangOptions &Options) { static llvm::cl::opt WarningsAsErrors("Werror", llvm::cl::desc("Treat all warnings as errors")); +static llvm::cl::opt +SilenceWarnings("w", llvm::cl::desc("Do not emit any warnings")); + static llvm::cl::opt WarnOnExtensions("pedantic", llvm::cl::init(false), llvm::cl::desc("Issue a warning on uses of GCC extensions")); @@ -492,6 +495,7 @@ WarnImplicitFunctionDeclaration("Wimplicit-function-declaration" /// InitializeDiagnostics - Initialize the diagnostic object, based on the /// current command line option settings. static void InitializeDiagnostics(Diagnostic &Diags) { + Diags.setIgnoreAllWarnings(SilenceWarnings); Diags.setWarningsAsErrors(WarningsAsErrors); Diags.setWarnOnExtensions(WarnOnExtensions); Diags.setErrorOnExtensions(ErrorOnExtensions); diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h index 4307955b2cf7..617702c7f9eb 100644 --- a/clang/include/clang/Basic/Diagnostic.h +++ b/clang/include/clang/Basic/Diagnostic.h @@ -57,6 +57,7 @@ public: }; private: + bool IgnoreAllWarnings; // Ignore all warnings: -w bool WarningsAsErrors; // Treat warnings like errors: bool WarnOnExtensions; // Enables warnings for gcc extensions: -pedantic. bool ErrorOnExtensions; // Error on extensions: -pedantic-errors. @@ -87,6 +88,11 @@ public: const DiagnosticClient &getClient() const { return Client; }; + /// setIgnoreAllWarnings - When set to true, any unmapped warnings are + /// ignored. If this and WarningsAsErrors are both set, then this one wins. + void setIgnoreAllWarnings(bool Val) { IgnoreAllWarnings = Val; } + bool getIgnoreAllWarnings() const { return IgnoreAllWarnings; } + /// setWarningsAsErrors - When set to true, any warnings reported are issued /// as errors. void setWarningsAsErrors(bool Val) { WarningsAsErrors = Val; } diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index 5835e75c1a7a..fbf118f27578 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/lib/Basic/Diagnostic.cpp @@ -108,6 +108,7 @@ namespace clang { //===----------------------------------------------------------------------===// Diagnostic::Diagnostic(DiagnosticClient &client) : Client(client) { + IgnoreAllWarnings = false; WarningsAsErrors = false; WarnOnExtensions = false; ErrorOnExtensions = false; @@ -167,7 +168,7 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const { if (DiagClass < ERROR) { switch (getDiagnosticMapping((diag::kind)DiagID)) { case diag::MAP_DEFAULT: break; - case diag::MAP_IGNORE: return Ignored; + case diag::MAP_IGNORE: return Diagnostic::Ignored; case diag::MAP_WARNING: DiagClass = WARNING; break; case diag::MAP_ERROR: DiagClass = ERROR; break; } @@ -183,9 +184,13 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const { return Ignored; } - // If warnings are to be treated as errors, indicate this as such. - if (DiagClass == WARNING && WarningsAsErrors) - DiagClass = ERROR; + // If warnings are globally mapped to ignore or error, do it. + if (DiagClass == WARNING) { + if (IgnoreAllWarnings) + return Diagnostic::Ignored; + if (WarningsAsErrors) + DiagClass = ERROR; + } switch (DiagClass) { default: assert(0 && "Unknown diagnostic class!");