aboutsummaryrefslogtreecommitdiff
path: root/Driver/DiagChecker.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2008-09-11 02:46:36 +0000
committerDouglas Gregor <dgregor@apple.com>2008-09-11 02:46:36 +0000
commit233f74b29b2864d5984e13f3ae10a21404ef82e8 (patch)
tree62c5dc21d04e21c9e44f4ead970c3639c21d3d29 /Driver/DiagChecker.cpp
parent8951dbd225580173193ec9db503d9d9844ff97d6 (diff)
Add support for expected-note to Clang's -verify option
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56089 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/DiagChecker.cpp')
-rw-r--r--Driver/DiagChecker.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/Driver/DiagChecker.cpp b/Driver/DiagChecker.cpp
index 660d17add2..6f7ea0b739 100644
--- a/Driver/DiagChecker.cpp
+++ b/Driver/DiagChecker.cpp
@@ -40,6 +40,7 @@ typedef TextDiagnosticBuffer::const_iterator const_diag_iterator;
static const char * const ExpectedErrStr = "expected-error";
static const char * const ExpectedWarnStr = "expected-warning";
+static const char * const ExpectedNoteStr = "expected-note";
/// FindDiagnostics - Go through the comment and see if it indicates expected
/// diagnostics. If so, then put them in a diagnostic list.
@@ -86,7 +87,8 @@ static void FindDiagnostics(const std::string &Comment,
// expected errors and warnings.
static void FindExpectedDiags(Preprocessor &PP,
DiagList &ExpectedErrors,
- DiagList &ExpectedWarnings) {
+ DiagList &ExpectedWarnings,
+ DiagList &ExpectedNotes) {
// Return comments as tokens, this is how we find expected diagnostics.
PP.SetCommentRetentionState(true, true);
@@ -114,6 +116,10 @@ static void FindExpectedDiags(Preprocessor &PP,
// Find all expected warnings
FindDiagnostics(Comment, ExpectedWarnings, PP.getSourceManager(),
Tok.getLocation(), ExpectedWarnStr);
+
+ // Find all expected notes
+ FindDiagnostics(Comment, ExpectedNotes, PP.getSourceManager(),
+ Tok.getLocation(), ExpectedNoteStr);
}
} while (Tok.isNot(tok::eof));
@@ -182,7 +188,8 @@ static bool CompareDiagLists(SourceManager &SourceMgr,
///
static bool CheckResults(Preprocessor &PP,
const DiagList &ExpectedErrors,
- const DiagList &ExpectedWarnings) {
+ const DiagList &ExpectedWarnings,
+ const DiagList &ExpectedNotes) {
const DiagnosticClient *DiagClient = PP.getDiagnostics().getClient();
assert(DiagClient != 0 &&
"DiagChecker requires a valid TextDiagnosticBuffer");
@@ -223,6 +230,20 @@ static bool CheckResults(Preprocessor &PP,
ExpectedWarnings.end(),
"Warnings seen but not expected:");
+ // See if there were notes that were expected but not seen.
+ HadProblem |= CompareDiagLists(SourceMgr,
+ ExpectedNotes.begin(),
+ ExpectedNotes.end(),
+ Diags.note_begin(), Diags.note_end(),
+ "Notes expected but not seen:");
+
+ // See if there were notes that were seen but not expected.
+ HadProblem |= CompareDiagLists(SourceMgr,
+ Diags.note_begin(), Diags.note_end(),
+ ExpectedNotes.begin(),
+ ExpectedNotes.end(),
+ "Notes seen but not expected:");
+
return HadProblem;
}
@@ -238,9 +259,9 @@ bool clang::CheckASTConsumer(Preprocessor &PP, ASTConsumer* C) {
/// CheckDiagnostics - Gather the expected diagnostics and check them.
bool clang::CheckDiagnostics(Preprocessor &PP) {
// Gather the set of expected diagnostics.
- DiagList ExpectedErrors, ExpectedWarnings;
- FindExpectedDiags(PP, ExpectedErrors, ExpectedWarnings);
+ DiagList ExpectedErrors, ExpectedWarnings, ExpectedNotes;
+ FindExpectedDiags(PP, ExpectedErrors, ExpectedWarnings, ExpectedNotes);
// Check that the expected diagnostics occurred.
- return CheckResults(PP, ExpectedErrors, ExpectedWarnings);
+ return CheckResults(PP, ExpectedErrors, ExpectedWarnings, ExpectedNotes);
}