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 @@ -830,7 +830,7 @@ static bool parseDiagnosticLevelMask(StringRef FlagName, const std::vector &Levels, - DiagnosticsEngine *Diags, + DiagnosticsEngine &Diags, DiagnosticLevelMask &M) { bool Success = true; for (const auto &Level : Levels) { @@ -843,8 +843,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; } @@ -1383,7 +1382,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 @@ -1393,10 +1392,8 @@ }); 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; @@ -1405,6 +1402,13 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, DiagnosticsEngine *Diags, bool DefaultDiagColor) { + Optional IgnoringDiags; + if (!Diags) { + IgnoringDiags.emplace(new DiagnosticIDs(), new DiagnosticOptions(), + new IgnoringDiagConsumer()); + Diags = &*IgnoringDiags; + } + bool Success = true; Opts.DiagnosticLogFile = @@ -1439,10 +1443,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 = @@ -1455,10 +1458,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 = @@ -1474,10 +1476,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); @@ -1488,7 +1489,7 @@ Opts.VerifyPrefixes.push_back("expected"); // Keep VerifyPrefixes in its original order for the sake of diagnostics, and // then sort it to prepare for fast lookup using std::binary_search. - if (!checkVerifyPrefixes(Opts.VerifyPrefixes, Diags)) { + if (!checkVerifyPrefixes(Opts.VerifyPrefixes, *Diags)) { Opts.VerifyDiagnostics = false; Success = false; } @@ -1497,7 +1498,7 @@ DiagnosticLevelMask DiagMask = DiagnosticLevelMask::None; Success &= parseDiagnosticLevelMask("-verify-ignore-unexpected=", Args.getAllArgValues(OPT_verify_ignore_unexpected_EQ), - Diags, DiagMask); + *Diags, DiagMask); if (Args.hasArg(OPT_verify_ignore_unexpected)) DiagMask = DiagnosticLevelMask::All; Opts.setVerifyIgnoreUnexpected(DiagMask); @@ -1523,9 +1524,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);