diff options
author | Andy Gibbs <andyg1001@hotmail.co.uk> | 2014-07-10 16:43:29 +0000 |
---|---|---|
committer | Andy Gibbs <andyg1001@hotmail.co.uk> | 2014-07-10 16:43:29 +0000 |
commit | c1f152ee6c5163cd19a4f695bbb4321da2a0149b (patch) | |
tree | c23601cf7fbe24fb9eeecbf30b3c256d2d8c96cd /clang/lib/Frontend/VerifyDiagnosticConsumer.cpp | |
parent | f4eba98853dbb8fa1adbd29a2e697f94818c5a7a (diff) | |
download | bcm5719-llvm-c1f152ee6c5163cd19a4f695bbb4321da2a0149b.tar.gz bcm5719-llvm-c1f152ee6c5163cd19a4f695bbb4321da2a0149b.zip |
Provide -verify support to match "any" line for diagnostics in included files.
Allow diagnostic checks that originate in included files to be matched without necessarily determining the line number that the diagnostic occurs on. The new syntax replaces the line number with '*'. This extension is limited to diagnostics in included files and may be used where the include file is not part of the test-suite itself.
Expected uses are for diagnostics originating in system headers, or for users who use -verify in testing 3rd-party library code where the location of diagnostics in header files may change from revision to revision and their precise location is not important to the success of the test-case.
llvm-svn: 212735
Diffstat (limited to 'clang/lib/Frontend/VerifyDiagnosticConsumer.cpp')
-rw-r--r-- | clang/lib/Frontend/VerifyDiagnosticConsumer.cpp | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp index 856b51db3dc..b50950e9b30 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -164,8 +164,9 @@ namespace { class StandardDirective : public Directive { public: StandardDirective(SourceLocation DirectiveLoc, SourceLocation DiagnosticLoc, - StringRef Text, unsigned Min, unsigned Max) - : Directive(DirectiveLoc, DiagnosticLoc, Text, Min, Max) { } + bool MatchAnyLine, StringRef Text, unsigned Min, + unsigned Max) + : Directive(DirectiveLoc, DiagnosticLoc, MatchAnyLine, Text, Min, Max) { } bool isValid(std::string &Error) override { // all strings are considered valid; even empty ones @@ -182,8 +183,10 @@ public: class RegexDirective : public Directive { public: RegexDirective(SourceLocation DirectiveLoc, SourceLocation DiagnosticLoc, - StringRef Text, unsigned Min, unsigned Max, StringRef RegexStr) - : Directive(DirectiveLoc, DiagnosticLoc, Text, Min, Max), Regex(RegexStr) { } + bool MatchAnyLine, StringRef Text, unsigned Min, unsigned Max, + StringRef RegexStr) + : Directive(DirectiveLoc, DiagnosticLoc, MatchAnyLine, Text, Min, Max), + Regex(RegexStr) { } bool isValid(std::string &Error) override { if (Regex.isValid(Error)) @@ -371,6 +374,7 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM, // Next optional token: @ SourceLocation ExpectedLoc; + bool MatchAnyLine = false; if (!PH.Next("@")) { ExpectedLoc = Pos; } else { @@ -411,6 +415,10 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM, if (PH.Next(Line) && Line > 0) ExpectedLoc = SM.translateFileLineCol(FE, Line, 1); + else if (PH.Next("*")) { + MatchAnyLine = true; + ExpectedLoc = SM.translateFileLineCol(FE, 1, 1); + } } if (ExpectedLoc.isInvalid()) { @@ -495,7 +503,8 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM, // Construct new directive. std::unique_ptr<Directive> D( - Directive::create(RegexKind, Pos, ExpectedLoc, Text, Min, Max)); + Directive::create(RegexKind, Pos, ExpectedLoc, MatchAnyLine, Text, + Min, Max)); std::string Error; if (D->isValid(Error)) { @@ -644,8 +653,11 @@ static unsigned PrintExpected(DiagnosticsEngine &Diags, SourceManager &SourceMgr llvm::raw_svector_ostream OS(Fmt); for (DirectiveList::iterator I = DL.begin(), E = DL.end(); I != E; ++I) { Directive &D = **I; - OS << "\n File " << SourceMgr.getFilename(D.DiagnosticLoc) - << " Line " << SourceMgr.getPresumedLineNumber(D.DiagnosticLoc); + OS << "\n File " << SourceMgr.getFilename(D.DiagnosticLoc); + if (D.MatchAnyLine) + OS << " Line *"; + else + OS << " Line " << SourceMgr.getPresumedLineNumber(D.DiagnosticLoc); if (D.DirectiveLoc != D.DiagnosticLoc) OS << " (directive at " << SourceMgr.getFilename(D.DirectiveLoc) << ':' @@ -692,9 +704,11 @@ static unsigned CheckLists(DiagnosticsEngine &Diags, SourceManager &SourceMgr, for (unsigned i = 0; i < D.Max; ++i) { DiagList::iterator II, IE; for (II = Right.begin(), IE = Right.end(); II != IE; ++II) { - unsigned LineNo2 = SourceMgr.getPresumedLineNumber(II->first); - if (LineNo1 != LineNo2) - continue; + if (!D.MatchAnyLine) { + unsigned LineNo2 = SourceMgr.getPresumedLineNumber(II->first); + if (LineNo1 != LineNo2) + continue; + } if (!IsFromSameFile(SourceMgr, D.DiagnosticLoc, II->first)) continue; @@ -859,10 +873,11 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() { } Directive *Directive::create(bool RegexKind, SourceLocation DirectiveLoc, - SourceLocation DiagnosticLoc, StringRef Text, - unsigned Min, unsigned Max) { + SourceLocation DiagnosticLoc, bool MatchAnyLine, + StringRef Text, unsigned Min, unsigned Max) { if (!RegexKind) - return new StandardDirective(DirectiveLoc, DiagnosticLoc, Text, Min, Max); + return new StandardDirective(DirectiveLoc, DiagnosticLoc, MatchAnyLine, + Text, Min, Max); // Parse the directive into a regular expression. std::string RegexStr; @@ -887,6 +902,6 @@ Directive *Directive::create(bool RegexKind, SourceLocation DirectiveLoc, } } - return new RegexDirective(DirectiveLoc, DiagnosticLoc, Text, Min, Max, - RegexStr); + return new RegexDirective(DirectiveLoc, DiagnosticLoc, MatchAnyLine, Text, + Min, Max, RegexStr); } |