diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h --- a/clang/include/clang/Frontend/CompilerInvocation.h +++ b/clang/include/clang/Frontend/CompilerInvocation.h @@ -55,10 +55,9 @@ /// Args must have been created from the OptTable returned by /// createCC1OptTable(). /// -/// When errors are encountered, return false and, if Diags is non-null, -/// report the error(s). +/// When errors are encountered, return false and report the error(s). bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args, - DiagnosticsEngine *Diags = nullptr, + DiagnosticsEngine &Diags, bool DefaultDiagColor = true); class CompilerInvocationBase { diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -828,7 +828,7 @@ static bool parseDiagnosticLevelMask(StringRef FlagName, const std::vector &Levels, - DiagnosticsEngine *Diags, + DiagnosticsEngine &Diags, DiagnosticLevelMask &M) { bool Success = true; for (const auto &Level : Levels) { @@ -841,8 +841,7 @@ .Default(DiagnosticLevelMask::None); if (PM == DiagnosticLevelMask::None) { Success = false; - if (Diags) - Diags->Report(diag::err_drv_invalid_value) << FlagName << Level; + Diags.Report(diag::err_drv_invalid_value) << FlagName << Level; } M = M | PM; } @@ -1381,7 +1380,7 @@ } static bool checkVerifyPrefixes(const std::vector &VerifyPrefixes, - DiagnosticsEngine *Diags) { + DiagnosticsEngine &Diags) { bool Success = true; for (const auto &Prefix : VerifyPrefixes) { // Every prefix must start with a letter and contain only alphanumeric @@ -1391,17 +1390,15 @@ }); if (BadChar != Prefix.end() || !isLetter(Prefix[0])) { Success = false; - if (Diags) { - Diags->Report(diag::err_drv_invalid_value) << "-verify=" << Prefix; - Diags->Report(diag::note_drv_verify_prefix_spelling); - } + Diags.Report(diag::err_drv_invalid_value) << "-verify=" << Prefix; + Diags.Report(diag::note_drv_verify_prefix_spelling); } } return Success; } bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, - DiagnosticsEngine *Diags, + DiagnosticsEngine &Diags, bool DefaultDiagColor) { bool Success = true; @@ -1437,10 +1434,9 @@ Opts.setShowOverloads(Ovl_All); else { Success = false; - if (Diags) - Diags->Report(diag::err_drv_invalid_value) - << Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args) - << ShowOverloads; + Diags.Report(diag::err_drv_invalid_value) + << Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args) + << ShowOverloads; } StringRef ShowCategory = @@ -1453,10 +1449,9 @@ Opts.ShowCategories = 2; else { Success = false; - if (Diags) - Diags->Report(diag::err_drv_invalid_value) - << Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args) - << ShowCategory; + Diags.Report(diag::err_drv_invalid_value) + << Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args) + << ShowCategory; } StringRef Format = @@ -1472,10 +1467,9 @@ Opts.setFormat(DiagnosticOptions::Vi); else { Success = false; - if (Diags) - Diags->Report(diag::err_drv_invalid_value) - << Args.getLastArg(OPT_fdiagnostics_format)->getAsString(Args) - << Format; + Diags.Report(diag::err_drv_invalid_value) + << Args.getLastArg(OPT_fdiagnostics_format)->getAsString(Args) + << Format; } Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info); @@ -1521,9 +1515,8 @@ DiagnosticOptions::DefaultTabStop, Diags); if (Opts.TabStop == 0 || Opts.TabStop > DiagnosticOptions::MaxTabStop) { Opts.TabStop = DiagnosticOptions::DefaultTabStop; - if (Diags) - Diags->Report(diag::warn_ignoring_ftabstop_value) - << Opts.TabStop << DiagnosticOptions::DefaultTabStop; + Diags.Report(diag::warn_ignoring_ftabstop_value) + << Opts.TabStop << DiagnosticOptions::DefaultTabStop; } Opts.MessageLength = getLastArgIntValue(Args, OPT_fmessage_length_EQ, 0, Diags); @@ -3056,7 +3049,7 @@ Diags.Report(diag::err_fe_dependency_file_requires_MT); Success = false; } - Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, &Diags, + Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, Diags, /*DefaultDiagColor=*/false); ParseCommentArgs(LangOpts.CommentOpts, Args); // FIXME: We shouldn't have to pass the DashX option around here diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp --- a/clang/lib/Tooling/Tooling.cpp +++ b/clang/lib/Tooling/Tooling.cpp @@ -328,7 +328,9 @@ unsigned MissingArgIndex, MissingArgCount; llvm::opt::InputArgList ParsedArgs = driver::getDriverOptTable().ParseArgs( ArrayRef(Argv).slice(1), MissingArgIndex, MissingArgCount); - ParseDiagnosticArgs(*DiagOpts, ParsedArgs); + DiagnosticsEngine DummyDiags(new DiagnosticIDs(), new DiagnosticOptions(), + new IgnoringDiagConsumer()); + ParseDiagnosticArgs(*DiagOpts, ParsedArgs, DummyDiags); TextDiagnosticPrinter DiagnosticPrinter( llvm::errs(), &*DiagOpts); DiagnosticsEngine Diagnostics( diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp --- a/clang/tools/driver/driver.cpp +++ b/clang/tools/driver/driver.cpp @@ -281,7 +281,9 @@ // We ignore MissingArgCount and the return value of ParseDiagnosticArgs. // Any errors that would be diagnosed here will also be diagnosed later, // when the DiagnosticsEngine actually exists. - (void)ParseDiagnosticArgs(*DiagOpts, Args); + DiagnosticsEngine DummyDiags(new DiagnosticIDs(), new DiagnosticOptions(), + new IgnoringDiagConsumer()); + (void)ParseDiagnosticArgs(*DiagOpts, Args, DummyDiags); UseNewCC1Process = Args.hasFlag(clang::driver::options::OPT_fno_integrated_cc1,