[cfe-commits] r100684 - in /cfe/trunk: include/clang/Basic/Diagnostic.h include/clang/Basic/DiagnosticCommonKinds.td lib/Basic/Diagnostic.cpp

Chris Lattner sabre at nondot.org
Wed Apr 7 13:21:58 PDT 2010


Author: lattner
Date: Wed Apr  7 15:21:58 2010
New Revision: 100684

URL: http://llvm.org/viewvc/llvm-project?rev=100684&view=rev
Log:
add capabilities to stop emitting errors after some limit.
Right now the limit is 0 (aka disabled)

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

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=100684&r1=100683&r2=100684&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Apr  7 15:21:58 2010
@@ -188,6 +188,7 @@
   bool ErrorsAsFatal;            // Treat errors like fatal errors.
   bool SuppressSystemWarnings;   // Suppress warnings in system headers.
   bool SuppressAllDiagnostics;   // Suppress all diagnostics.
+  unsigned MaxErrorsEmitted;     // Cap of # errors emitted, 0 -> no limit.
   ExtensionHandling ExtBehavior; // Map extensions onto warnings or errors?
   DiagnosticClient *Client;
 
@@ -270,6 +271,10 @@
 
   void setClient(DiagnosticClient* client) { Client = client; }
 
+  /// setMaxErrorsEmitted - Specify a limit for the number of errors we should
+  /// emit before giving up.  Zero disables the limit.
+  void setMaxErrorsEmitted(unsigned Limit) { MaxErrorsEmitted = Limit; }
+  
   /// 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; }

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=100684&r1=100683&r2=100684&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Wed Apr  7 15:21:58 2010
@@ -13,6 +13,11 @@
 
 let Component = "Common" in {
 
+// Basic.
+
+def fatal_too_many_errors
+  : Error<"too many errors emitted, stopping now">, DefaultFatal; 
+
 def note_previous_definition : Note<"previous definition is here">;
 def note_previous_declaration : Note<"previous declaration is here">;
 def note_previous_implicit_declaration : Note<

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=100684&r1=100683&r2=100684&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Wed Apr  7 15:21:58 2010
@@ -223,6 +223,7 @@
 
   ErrorOccurred = false;
   FatalErrorOccurred = false;
+  MaxErrorsEmitted = 0;
   
   NumWarnings = 0;
   NumErrors = 0;
@@ -551,6 +552,12 @@
   if (DiagLevel >= Diagnostic::Error) {
     ErrorOccurred = true;
     ++NumErrors;
+    
+    // If we've emitted a lot of errors, emit a fatal error after it to stop a
+    // flood of bogus errors.
+    if (MaxErrorsEmitted && NumErrors >= MaxErrorsEmitted &&
+        DiagLevel == Diagnostic::Error)
+      SetDelayedDiagnostic(diag::fatal_too_many_errors);
   }
 
   // Finally, report it.





More information about the cfe-commits mailing list