[cfe-dev] -Wfatal-errors
Christian Adåker
cadaker at gmail.com
Fri Dec 18 02:11:02 PST 2009
Hi.
I was looking through the TODO file for some simple way of
contributing to clang, and saw a note about the -Wfatal-errors flag.
It turned out to be pretty straightforward to fix (by looking at
-Werror), but I thought I'd send the patch here for comments in case
I've missed something.
If everything's fine I'll do the -Wfatal-errors= version too. That
should be pretty much mimicking -Werror=, right?
//Christian Adåker
-------------- next part --------------
Index: include/clang/Basic/Diagnostic.h
===================================================================
--- include/clang/Basic/Diagnostic.h (revision 91675)
+++ include/clang/Basic/Diagnostic.h (working copy)
@@ -178,6 +178,7 @@
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 +261,11 @@
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: lib/Frontend/Warnings.cpp
===================================================================
--- lib/Frontend/Warnings.cpp (revision 91675)
+++ lib/Frontend/Warnings.cpp (working copy)
@@ -47,7 +47,7 @@
else
Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Ignore);
- // FIXME: -Wfatal-errors / -Wfatal-errors=foo
+ // FIXME: -Wfatal-errors=foo
for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i) {
const std::string &Opt = Opts.Warnings[i];
@@ -98,6 +98,12 @@
OptStart = Specifier;
}
+ // -Wfatal-errors is yet another special case.
+ if (OptEnd-OptStart == 12 && memcmp(OptStart, "fatal-errors", 12) == 0) {
+ Diags.setErrorsAsFatal(isPositive);
+ continue;
+ }
+
if (Diags.setDiagnosticGroupMapping(OptStart, Mapping))
Diags.Report(diag::warn_unknown_warning_option) << ("-W" + Opt);
}
Index: lib/Basic/Diagnostic.cpp
===================================================================
--- lib/Basic/Diagnostic.cpp (revision 91675)
+++ lib/Basic/Diagnostic.cpp (working copy)
@@ -203,6 +203,7 @@
AllExtensionsSilenced = 0;
IgnoreAllWarnings = false;
WarningsAsErrors = false;
+ ErrorsAsFatal = false;
SuppressSystemWarnings = false;
SuppressAllDiagnostics = false;
ExtBehavior = Ext_Ignore;
@@ -329,6 +330,8 @@
break;
case diag::MAP_ERROR:
Result = Diagnostic::Error;
+ if (ErrorsAsFatal)
+ Result = Diagnostic::Fatal;
break;
case diag::MAP_FATAL:
Result = Diagnostic::Fatal;
@@ -349,6 +352,8 @@
if (WarningsAsErrors)
Result = Diagnostic::Error;
+ if (Result == Diagnostic::Error && ErrorsAsFatal)
+ Result = Diagnostic::Fatal;
break;
case diag::MAP_WARNING_NO_WERROR:
More information about the cfe-dev
mailing list