aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-04-07 20:21:58 +0000
committerChris Lattner <sabre@nondot.org>2010-04-07 20:21:58 +0000
commitb205ac9fcd22b87b41697172d1983c5ae9dabaaf (patch)
treea8166792e9e05aed0654e5d312e7e58e9daab2db
parentc46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5 (diff)
add capabilities to stop emitting errors after some limit.
Right now the limit is 0 (aka disabled) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100684 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/Diagnostic.h5
-rw-r--r--include/clang/Basic/DiagnosticCommonKinds.td5
-rw-r--r--lib/Basic/Diagnostic.cpp7
3 files changed, 17 insertions, 0 deletions
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h
index 9279871997..8eb68a396a 100644
--- a/include/clang/Basic/Diagnostic.h
+++ b/include/clang/Basic/Diagnostic.h
@@ -188,6 +188,7 @@ private:
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 @@ public:
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; }
diff --git a/include/clang/Basic/DiagnosticCommonKinds.td b/include/clang/Basic/DiagnosticCommonKinds.td
index 8e791c3422..1402e96ce0 100644
--- a/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/include/clang/Basic/DiagnosticCommonKinds.td
@@ -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<
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index a1094ad95c..388875cf63 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -223,6 +223,7 @@ Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) {
ErrorOccurred = false;
FatalErrorOccurred = false;
+ MaxErrorsEmitted = 0;
NumWarnings = 0;
NumErrors = 0;
@@ -551,6 +552,12 @@ bool Diagnostic::ProcessDiag() {
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.