diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Frontend/DiagnosticOptions.h | 22 | ||||
-rw-r--r-- | clang/include/clang/Frontend/Utils.h | 6 | ||||
-rw-r--r-- | clang/lib/Frontend/Warnings.cpp | 15 | ||||
-rw-r--r-- | clang/tools/clang-cc/Options.cpp | 23 | ||||
-rw-r--r-- | clang/tools/clang-cc/clang-cc.cpp | 28 |
5 files changed, 51 insertions, 43 deletions
diff --git a/clang/include/clang/Frontend/DiagnosticOptions.h b/clang/include/clang/Frontend/DiagnosticOptions.h index 39dc48ebfe8..704769ec123 100644 --- a/clang/include/clang/Frontend/DiagnosticOptions.h +++ b/clang/include/clang/Frontend/DiagnosticOptions.h @@ -19,6 +19,10 @@ namespace clang { /// engine. class DiagnosticOptions { public: + unsigned IgnoreWarnings : 1; /// -w + unsigned NoRewriteMacros : 1; /// -Wno-rewrite-macros + unsigned Pedantic : 1; /// -pedantic + unsigned PedanticErrors : 1; /// -pedantic-errors unsigned ShowColumn : 1; /// Show column number on diagnostics. unsigned ShowLocation : 1; /// Show source location information. unsigned ShowCarets : 1; /// Show carets in diagnostics. @@ -35,16 +39,24 @@ public: /// testing and analysis. std::string DumpBuildInformation; + /// The list of -W... options used to alter the diagnostic mappings, with the + /// prefixes removed. + std::vector<std::string> Warnings; + public: DiagnosticOptions() { - ShowColumn = 1; - ShowLocation = 1; + IgnoreWarnings = 0; + MessageLength = 0; + NoRewriteMacros = 0; + Pedantic = 0; + PedanticErrors = 0; ShowCarets = 1; + ShowColors = 0; + ShowColumn = 1; ShowFixits = 1; - ShowSourceRanges = 0; + ShowLocation = 1; ShowOptionNames = 0; - ShowColors = 0; - MessageLength = 0; + ShowSourceRanges = 0; } }; diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 4bda8bd71dc..27c14c91701 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -29,6 +29,7 @@ class ASTConsumer; class Decl; class DependencyOutputOptions; class Diagnostic; +class DiagnosticOptions; class HeaderSearch; class HeaderSearchOptions; class IdentifierTable; @@ -59,10 +60,7 @@ void InitializePreprocessor(Preprocessor &PP, /// ProcessWarningOptions - Initialize the diagnostic client and process the /// warning options specified on the command line. -bool ProcessWarningOptions(Diagnostic &Diags, - std::vector<std::string> &Warnings, - bool Pedantic, bool PedanticErrors, - bool NoWarnings); +bool ProcessWarningOptions(Diagnostic &Diags, const DiagnosticOptions &Opts); /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream* OS, diff --git a/clang/lib/Frontend/Warnings.cpp b/clang/lib/Frontend/Warnings.cpp index 3f442c8a7fa..ff44c905166 100644 --- a/clang/lib/Frontend/Warnings.cpp +++ b/clang/lib/Frontend/Warnings.cpp @@ -24,6 +24,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Sema/SemaDiagnostic.h" #include "clang/Lex/LexDiagnostic.h" +#include "clang/Frontend/DiagnosticOptions.h" #include "clang/Frontend/FrontendDiagnostic.h" #include <cstdio> #include <cstring> @@ -32,26 +33,24 @@ using namespace clang; bool clang::ProcessWarningOptions(Diagnostic &Diags, - std::vector<std::string> &Warnings, - bool Pedantic, bool PedanticErrors, - bool NoWarnings) { + const DiagnosticOptions &Opts) { Diags.setSuppressSystemWarnings(true); // Default to -Wno-system-headers - Diags.setIgnoreAllWarnings(NoWarnings); + Diags.setIgnoreAllWarnings(Opts.IgnoreWarnings); // If -pedantic or -pedantic-errors was specified, then we want to map all // extension diagnostics onto WARNING or ERROR unless the user has futz'd // around with them explicitly. - if (PedanticErrors) + if (Opts.PedanticErrors) Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Error); - else if (Pedantic) + else if (Opts.Pedantic) Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Warn); else Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Ignore); // FIXME: -Wfatal-errors / -Wfatal-errors=foo - for (unsigned i = 0, e = Warnings.size(); i != e; ++i) { - const std::string &Opt = Warnings[i]; + for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i) { + const std::string &Opt = Opts.Warnings[i]; const char *OptStart = &Opt[0]; const char *OptEnd = OptStart+Opt.size(); assert(*OptEnd == 0 && "Expect null termination for lower-bound search"); diff --git a/clang/tools/clang-cc/Options.cpp b/clang/tools/clang-cc/Options.cpp index 7c716406ce0..de2122a892a 100644 --- a/clang/tools/clang-cc/Options.cpp +++ b/clang/tools/clang-cc/Options.cpp @@ -245,6 +245,18 @@ NoDiagnosticsFixIt("fno-diagnostics-fixit-info", llvm::cl::desc("Do not include fixit information in" " diagnostics")); +static llvm::cl::opt<bool> OptNoWarnings("w"); + +static llvm::cl::opt<bool> OptPedantic("pedantic"); + +static llvm::cl::opt<bool> OptPedanticErrors("pedantic-errors"); + +// This gets all -W options, including -Werror, -W[no-]system-headers, etc. The +// driver has stripped off -Wa,foo etc. The driver has also translated -W to +// -Wextra, so we don't need to worry about it. +static llvm::cl::list<std::string> +OptWarnings("W", llvm::cl::Prefix, llvm::cl::ValueOptional); + static llvm::cl::opt<bool> PrintSourceRangeInfo("fdiagnostics-print-source-range-info", llvm::cl::desc("Print source range spans in numeric form")); @@ -263,6 +275,10 @@ static llvm::cl::opt<bool> PrintColorDiagnostic("fcolor-diagnostics", llvm::cl::desc("Use colors in diagnostics")); +static llvm::cl::opt<bool> +SilenceRewriteMacroWarning("Wno-rewrite-macros", llvm::cl::init(false), + llvm::cl::desc("Silence ObjC rewriting warnings")); + } //===----------------------------------------------------------------------===// @@ -664,8 +680,14 @@ void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) { void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) { using namespace diagnosticoptions; + Opts.Warnings.insert(Opts.Warnings.begin(), + OptWarnings.begin(), OptWarnings.end()); Opts.DumpBuildInformation = DumpBuildInformation; + Opts.IgnoreWarnings = OptNoWarnings; Opts.MessageLength = MessageLength; + Opts.NoRewriteMacros = SilenceRewriteMacroWarning; + Opts.Pedantic = OptPedantic; + Opts.PedanticErrors = OptPedanticErrors; Opts.ShowCarets = !NoCaretDiagnostics; Opts.ShowColors = PrintColorDiagnostic; Opts.ShowColumn = !NoShowColumn; @@ -1106,4 +1128,3 @@ clang::InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts) { Opts.ShowComments = EnableCommentOutput; Opts.ShowMacroComments = EnableMacroCommentOutput; } - diff --git a/clang/tools/clang-cc/clang-cc.cpp b/clang/tools/clang-cc/clang-cc.cpp index f2b38401e7b..ad557535272 100644 --- a/clang/tools/clang-cc/clang-cc.cpp +++ b/clang/tools/clang-cc/clang-cc.cpp @@ -428,28 +428,6 @@ FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"), llvm::cl::desc("Perform Fix-It modifications at the given source location")); //===----------------------------------------------------------------------===// -// ObjC Rewriter Options -//===----------------------------------------------------------------------===// - -static llvm::cl::opt<bool> -SilenceRewriteMacroWarning("Wno-rewrite-macros", llvm::cl::init(false), - llvm::cl::desc("Silence ObjC rewriting warnings")); - -//===----------------------------------------------------------------------===// -// Warning Options -//===----------------------------------------------------------------------===// - -// This gets all -W options, including -Werror, -W[no-]system-headers, etc. The -// driver has stripped off -Wa,foo etc. The driver has also translated -W to -// -Wextra, so we don't need to worry about it. -static llvm::cl::list<std::string> -OptWarnings("W", llvm::cl::Prefix, llvm::cl::ValueOptional); - -static llvm::cl::opt<bool> OptPedantic("pedantic"); -static llvm::cl::opt<bool> OptPedanticErrors("pedantic-errors"); -static llvm::cl::opt<bool> OptNoWarnings("w"); - -//===----------------------------------------------------------------------===// // Dump Build Information //===----------------------------------------------------------------------===// @@ -596,7 +574,8 @@ static ASTConsumer *CreateConsumerAction(const CompilerInvocation &CompOpts, case RewriteObjC: OS.reset(ComputeOutFile(CompOpts, InFile, "cpp", true, OutPath)); return CreateObjCRewriter(InFile, OS.get(), PP.getDiagnostics(), - PP.getLangOptions(), SilenceRewriteMacroWarning); + PP.getLangOptions(), + CompOpts.getDiagnosticOpts().NoRewriteMacros); case RewriteBlocks: return CreateBlockRewriter(InFile, PP.getDiagnostics(), @@ -1079,8 +1058,7 @@ static Diagnostic *CreateDiagnosticEngine(const DiagnosticOptions &Opts, // Configure our handling of diagnostics. Diagnostic *Diags = new Diagnostic(DiagClient.take()); - if (ProcessWarningOptions(*Diags, OptWarnings, OptPedantic, OptPedanticErrors, - OptNoWarnings)) + if (ProcessWarningOptions(*Diags, Opts)) return 0; // Set an error handler, so that any LLVM backend diagnostics go through our |