diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Basic/CMakeLists.txt | 1 | ||||
-rw-r--r-- | clang/lib/Basic/DiagnosticOptions.cpp | 24 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 32 | ||||
-rw-r--r-- | clang/lib/Frontend/VerifyDiagnosticConsumer.cpp | 41 |
4 files changed, 85 insertions, 13 deletions
diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt index 50a06d9e7a4..cfad8c3649e 100644 --- a/clang/lib/Basic/CMakeLists.txt +++ b/clang/lib/Basic/CMakeLists.txt @@ -61,6 +61,7 @@ add_clang_library(clangBasic CharInfo.cpp Diagnostic.cpp DiagnosticIDs.cpp + DiagnosticOptions.cpp FileManager.cpp FileSystemStatCache.cpp IdentifierTable.cpp diff --git a/clang/lib/Basic/DiagnosticOptions.cpp b/clang/lib/Basic/DiagnosticOptions.cpp new file mode 100644 index 00000000000..f54a0ef4edb --- /dev/null +++ b/clang/lib/Basic/DiagnosticOptions.cpp @@ -0,0 +1,24 @@ +//===--- DiagnosticOptions.cpp - C Language Family Diagnostic Handling ----===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the DiagnosticOptions related interfaces. +// +//===----------------------------------------------------------------------===// + +#include "clang/Basic/DiagnosticOptions.h" +#include "llvm/Support/raw_ostream.h" + +namespace clang { + +raw_ostream& operator<<(raw_ostream& Out, DiagnosticLevelMask M) { + using UT = std::underlying_type<DiagnosticLevelMask>::type; + return Out << static_cast<UT>(M); +} + +} // end namespace clang diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 930c771a282..f4480bb2898 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -321,6 +321,29 @@ GenerateOptimizationRemarkRegex(DiagnosticsEngine &Diags, ArgList &Args, return Pattern; } +static bool parseDiagnosticLevelMask(StringRef FlagName, + const std::vector<std::string> &Levels, + DiagnosticsEngine *Diags, + DiagnosticLevelMask &M) { + bool Success = true; + for (const auto &Level : Levels) { + DiagnosticLevelMask const PM = + llvm::StringSwitch<DiagnosticLevelMask>(Level) + .Case("note", DiagnosticLevelMask::Note) + .Case("remark", DiagnosticLevelMask::Remark) + .Case("warning", DiagnosticLevelMask::Warning) + .Case("error", DiagnosticLevelMask::Error) + .Default(DiagnosticLevelMask::None); + if (PM == DiagnosticLevelMask::None) { + Success = false; + if (Diags) + Diags->Report(diag::err_drv_invalid_value) << FlagName << Level; + } + M = M | PM; + } + return Success; +} + static void parseSanitizerKinds(StringRef FlagName, const std::vector<std::string> &Sanitizers, DiagnosticsEngine &Diags, SanitizerSet &S) { @@ -748,11 +771,18 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, << Args.getLastArg(OPT_fdiagnostics_format)->getAsString(Args) << Format; } - + Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info); Opts.ShowParseableFixits = Args.hasArg(OPT_fdiagnostics_parseable_fixits); Opts.ShowPresumedLoc = !Args.hasArg(OPT_fno_diagnostics_use_presumed_location); Opts.VerifyDiagnostics = Args.hasArg(OPT_verify); + DiagnosticLevelMask DiagMask = DiagnosticLevelMask::None; + Success &= parseDiagnosticLevelMask("-verify-ignore-unexpected=", + Args.getAllArgValues(OPT_verify_ignore_unexpected_EQ), + Diags, DiagMask); + if (Args.hasArg(OPT_verify_ignore_unexpected)) + DiagMask = DiagnosticLevelMask::All; + Opts.setVerifyIgnoreUnexpected(DiagMask); Opts.ElideType = !Args.hasArg(OPT_fno_elide_type); Opts.ShowTemplateTree = Args.hasArg(OPT_fdiagnostics_show_template_tree); Opts.ErrorLimit = getLastArgIntValue(Args, OPT_ferror_limit, 0, Diags); diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp index 910e394553d..55df9361b58 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -691,7 +691,8 @@ static unsigned CheckLists(DiagnosticsEngine &Diags, SourceManager &SourceMgr, const char *Label, DirectiveList &Left, const_diag_iterator d2_begin, - const_diag_iterator d2_end) { + const_diag_iterator d2_end, + bool IgnoreUnexpected) { std::vector<Directive *> LeftOnly; DiagList Right(d2_begin, d2_end); @@ -727,7 +728,8 @@ static unsigned CheckLists(DiagnosticsEngine &Diags, SourceManager &SourceMgr, } // Now all that's left in Right are those that were not matched. unsigned num = PrintExpected(Diags, SourceMgr, LeftOnly, Label); - num += PrintUnexpected(Diags, &SourceMgr, Right.begin(), Right.end(), Label); + if (!IgnoreUnexpected) + num += PrintUnexpected(Diags, &SourceMgr, Right.begin(), Right.end(), Label); return num; } @@ -745,21 +747,28 @@ static unsigned CheckResults(DiagnosticsEngine &Diags, SourceManager &SourceMgr, // Seen \ Expected - set seen but not expected unsigned NumProblems = 0; + const DiagnosticLevelMask DiagMask = + Diags.getDiagnosticOptions().getVerifyIgnoreUnexpected(); + // See if there are error mismatches. NumProblems += CheckLists(Diags, SourceMgr, "error", ED.Errors, - Buffer.err_begin(), Buffer.err_end()); + Buffer.err_begin(), Buffer.err_end(), + bool(DiagnosticLevelMask::Error & DiagMask)); // See if there are warning mismatches. NumProblems += CheckLists(Diags, SourceMgr, "warning", ED.Warnings, - Buffer.warn_begin(), Buffer.warn_end()); + Buffer.warn_begin(), Buffer.warn_end(), + bool(DiagnosticLevelMask::Warning & DiagMask)); // See if there are remark mismatches. NumProblems += CheckLists(Diags, SourceMgr, "remark", ED.Remarks, - Buffer.remark_begin(), Buffer.remark_end()); + Buffer.remark_begin(), Buffer.remark_end(), + bool(DiagnosticLevelMask::Remark & DiagMask)); // See if there are note mismatches. NumProblems += CheckLists(Diags, SourceMgr, "note", ED.Notes, - Buffer.note_begin(), Buffer.note_end()); + Buffer.note_begin(), Buffer.note_end(), + bool(DiagnosticLevelMask::Note & DiagMask)); return NumProblems; } @@ -854,12 +863,20 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() { // Check that the expected diagnostics occurred. NumErrors += CheckResults(Diags, *SrcManager, *Buffer, ED); } else { - NumErrors += (PrintUnexpected(Diags, nullptr, Buffer->err_begin(), - Buffer->err_end(), "error") + - PrintUnexpected(Diags, nullptr, Buffer->warn_begin(), - Buffer->warn_end(), "warn") + - PrintUnexpected(Diags, nullptr, Buffer->note_begin(), - Buffer->note_end(), "note")); + const DiagnosticLevelMask DiagMask = + ~Diags.getDiagnosticOptions().getVerifyIgnoreUnexpected(); + if (bool(DiagnosticLevelMask::Error & DiagMask)) + NumErrors += PrintUnexpected(Diags, nullptr, Buffer->err_begin(), + Buffer->err_end(), "error"); + if (bool(DiagnosticLevelMask::Warning & DiagMask)) + NumErrors += PrintUnexpected(Diags, nullptr, Buffer->warn_begin(), + Buffer->warn_end(), "warn"); + if (bool(DiagnosticLevelMask::Remark & DiagMask)) + NumErrors += PrintUnexpected(Diags, nullptr, Buffer->remark_begin(), + Buffer->remark_end(), "remark"); + if (bool(DiagnosticLevelMask::Note & DiagMask)) + NumErrors += PrintUnexpected(Diags, nullptr, Buffer->note_begin(), + Buffer->note_end(), "note"); } Diags.setClient(CurClient, Owner.release() != nullptr); |