]> granicus.if.org Git - clang/commitdiff
implement -W[no-]fatal-errors, patch by Christian Adåker!
authorChris Lattner <sabre@nondot.org>
Tue, 22 Dec 2009 23:12:53 +0000 (23:12 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 22 Dec 2009 23:12:53 +0000 (23:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91938 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Diagnostic.h
lib/Basic/Diagnostic.cpp
lib/Frontend/Warnings.cpp

index b2523f28d5e0153fd3e72ad721c1c419d5a8c658..9c69b59c6c52acf5e8b475b5c331ab6ce9991c78 100644 (file)
@@ -76,7 +76,10 @@ namespace clang {
 
       /// Map this diagnostic to "warning", but make it immune to -Werror.  This
       /// happens when you specify -Wno-error=foo.
-      MAP_WARNING_NO_WERROR = 5
+      MAP_WARNING_NO_WERROR = 5,
+      /// Map this diagnostic to "error", but make it immune to -Wfatal-errors.
+      /// This happens for -Wno-fatal-errors=foo.
+      MAP_ERROR_NO_WFATAL = 6
     };
   }
 
@@ -178,6 +181,7 @@ private:
   unsigned char AllExtensionsSilenced; // Used by __extension__
   bool IgnoreAllWarnings;        // Ignore all warnings: -w
   bool WarningsAsErrors;         // Treat warnings like errors:
+  bool ErrorsAsFatal;            // Treat errors like fatal errors.
   bool SuppressSystemWarnings;   // Suppress warnings in system headers.
   bool SuppressAllDiagnostics;   // Suppress all diagnostics.
   ExtensionHandling ExtBehavior; // Map extensions onto warnings or errors?
@@ -260,6 +264,11 @@ public:
   void setWarningsAsErrors(bool Val) { WarningsAsErrors = Val; }
   bool getWarningsAsErrors() const { return WarningsAsErrors; }
 
+  /// setErrorsAsFatal - When set to true, any error reported is made a
+  /// fatal error.
+  void setErrorsAsFatal(bool Val) { ErrorsAsFatal = Val; }
+  bool getErrorsAsFatal() const { return ErrorsAsFatal; }
+
   /// setSuppressSystemWarnings - When set to true mask warnings that
   /// come from system headers.
   void setSuppressSystemWarnings(bool Val) { SuppressSystemWarnings = Val; }
index 8d0d81326db0f8ffa3e02b6ebf4eadfb08bf0104..4351f66be32f253aa5536ff35d8f417da09b3283 100644 (file)
@@ -203,6 +203,7 @@ Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) {
   AllExtensionsSilenced = 0;
   IgnoreAllWarnings = false;
   WarningsAsErrors = false;
+  ErrorsAsFatal = false;
   SuppressSystemWarnings = false;
   SuppressAllDiagnostics = false;
   ExtBehavior = Ext_Ignore;
@@ -326,9 +327,13 @@ Diagnostic::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass) const {
       return Diagnostic::Ignored;
     Result = Diagnostic::Warning;
     if (ExtBehavior == Ext_Error) Result = Diagnostic::Error;
+    if (Result == Diagnostic::Error && ErrorsAsFatal)
+      Result = Diagnostic::Fatal;
     break;
   case diag::MAP_ERROR:
     Result = Diagnostic::Error;
+    if (ErrorsAsFatal)
+      Result = Diagnostic::Fatal;
     break;
   case diag::MAP_FATAL:
     Result = Diagnostic::Fatal;
@@ -349,6 +354,8 @@ Diagnostic::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass) const {
 
     if (WarningsAsErrors)
       Result = Diagnostic::Error;
+    if (Result == Diagnostic::Error && ErrorsAsFatal)
+      Result = Diagnostic::Fatal;
     break;
 
   case diag::MAP_WARNING_NO_WERROR:
@@ -361,6 +368,12 @@ Diagnostic::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass) const {
       return Diagnostic::Ignored;
 
     break;
+
+  case diag::MAP_ERROR_NO_WFATAL:
+    // Diagnostics specified as -Wno-fatal-error=foo should be errors, but
+    // unaffected by -Wfatal-errors.
+    Result = Diagnostic::Error;
+    break;
   }
 
   // Okay, we're about to return this as a "diagnostic to emit" one last check:
index ff44c90516637d3858330c713850467d556ad0f0..4d12bcf7e0f98ade59995f8a6738cebbd1975755 100644 (file)
@@ -47,8 +47,6 @@ bool clang::ProcessWarningOptions(Diagnostic &Diags,
   else
     Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Ignore);
 
-  // FIXME: -Wfatal-errors / -Wfatal-errors=foo
-
   for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i) {
     const std::string &Opt = Opts.Warnings[i];
     const char *OptStart = &Opt[0];
@@ -98,6 +96,31 @@ bool clang::ProcessWarningOptions(Diagnostic &Diags,
       OptStart = Specifier;
     }
 
+    // -Wfatal-errors is yet another special case.
+    if (OptEnd-OptStart >= 12 && memcmp(OptStart, "fatal-errors", 12) == 0) {
+      const char* Specifier = 0;
+      if (OptEnd-OptStart != 12) {
+        if ((OptStart[12] != '=' && OptStart[12] != '-') ||
+            OptEnd-OptStart == 13) {
+          fprintf(stderr,
+                  "warning: unknown -Wfatal-errors warning specifier: -W%s\n",
+                  Opt.c_str());
+          continue;
+        }
+        Specifier = OptStart + 13;
+      }
+
+      if (Specifier == 0) {
+        Diags.setErrorsAsFatal(isPositive);
+        continue;
+      }
+
+      // -Wfatal-errors=foo maps foo to Fatal, -Wno-fatal-errors=foo
+      // maps it to Error.
+      Mapping = isPositive ? diag::MAP_FATAL : diag::MAP_ERROR_NO_WFATAL;
+      OptStart = Specifier;
+    }
+
     if (Diags.setDiagnosticGroupMapping(OptStart, Mapping))
       Diags.Report(diag::warn_unknown_warning_option) << ("-W" + Opt);
   }