Implement support for -w, which silences all warnings. PR2384.

llvm-svn: 51683
This commit is contained in:
Chris Lattner 2008-05-29 15:36:45 +00:00
parent 43a6d51494
commit 8c80070de2
3 changed files with 19 additions and 4 deletions

View File

@ -461,6 +461,9 @@ void InitializeGCMode(LangOptions &Options) {
static llvm::cl::opt<bool>
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 @@ WarnImplicitFunctionDeclaration("Wimplicit-function-declaration"
/// 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);

View File

@ -57,6 +57,7 @@ public:
};
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 @@ public:
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; }

View File

@ -108,6 +108,7 @@ namespace clang {
//===----------------------------------------------------------------------===//
Diagnostic::Diagnostic(DiagnosticClient &client) : Client(client) {
IgnoreAllWarnings = false;
WarningsAsErrors = false;
WarnOnExtensions = false;
ErrorOnExtensions = false;
@ -167,7 +168,7 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const {
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 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const {
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!");