[cfe-commits] r51683 - in /cfe/trunk: Driver/clang.cpp include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp

Chris Lattner sabre at nondot.org
Thu May 29 08:36:45 PDT 2008


Author: lattner
Date: Thu May 29 10:36:45 2008
New Revision: 51683

URL: http://llvm.org/viewvc/llvm-project?rev=51683&view=rev
Log:
Implement support for -w, which silences all warnings. PR2384.

Modified:
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/lib/Basic/Diagnostic.cpp

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=51683&r1=51682&r2=51683&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Thu May 29 10:36:45 2008
@@ -462,6 +462,9 @@
 WarningsAsErrors("Werror", llvm::cl::desc("Treat all warnings as errors"));
 
 static llvm::cl::opt<bool>
+SilenceWarnings("w", llvm::cl::desc("Do not emit any warnings"));
+
+static llvm::cl::opt<bool>
 WarnOnExtensions("pedantic", llvm::cl::init(false),
                  llvm::cl::desc("Issue a warning on uses of GCC extensions"));
 
@@ -492,6 +495,7 @@
 /// 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);

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=51683&r1=51682&r2=51683&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Thu May 29 10:36:45 2008
@@ -57,6 +57,7 @@
   };
   
 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 @@
   
   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; }

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=51683&r1=51682&r2=51683&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Thu May 29 10:36:45 2008
@@ -108,6 +108,7 @@
 //===----------------------------------------------------------------------===//
 
 Diagnostic::Diagnostic(DiagnosticClient &client) : Client(client) {
+  IgnoreAllWarnings = false;
   WarningsAsErrors = false;
   WarnOnExtensions = false;
   ErrorOnExtensions = false;
@@ -167,7 +168,7 @@
   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 @@
       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!");





More information about the cfe-commits mailing list