Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- DiagChecker.cpp - Diagnostic Checking Functions ------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Process the input files and check that the diagnostic messages are expected. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Eli Friedman | b09f6e1 | 2009-05-19 04:14:29 +0000 | [diff] [blame] | 14 | #include "clang/Frontend/Utils.h" |
Daniel Dunbar | e1bd4e6 | 2009-03-02 06:16:29 +0000 | [diff] [blame] | 15 | #include "clang/Frontend/TextDiagnosticBuffer.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 16 | #include "clang/Parse/ParseAST.h" |
Chris Lattner | 556beb7 | 2007-09-15 22:56:56 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTConsumer.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 18 | #include "clang/Basic/SourceManager.h" |
| 19 | #include "clang/Lex/Preprocessor.h" |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
| 23 | typedef TextDiagnosticBuffer::DiagList DiagList; |
| 24 | typedef TextDiagnosticBuffer::const_iterator const_diag_iterator; |
| 25 | |
Chris Lattner | b2c8c55 | 2008-11-23 23:38:26 +0000 | [diff] [blame] | 26 | static void EmitError(Preprocessor &PP, SourceLocation Pos, const char *String){ |
| 27 | unsigned ID = PP.getDiagnostics().getCustomDiagID(Diagnostic::Error, String); |
| 28 | PP.Diag(Pos, ID); |
| 29 | } |
| 30 | |
| 31 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 32 | // USING THE DIAGNOSTIC CHECKER: |
| 33 | // |
| 34 | // Indicating that a line expects an error or a warning is simple. Put a comment |
| 35 | // on the line that has the diagnostic, use "expected-{error,warning}" to tag |
| 36 | // if it's an expected error or warning, and place the expected text between {{ |
| 37 | // and }} markers. The full text doesn't have to be included, only enough to |
| 38 | // ensure that the correct diagnostic was emitted. |
| 39 | // |
| 40 | // Here's an example: |
| 41 | // |
| 42 | // int A = B; // expected-error {{use of undeclared identifier 'B'}} |
| 43 | // |
| 44 | // You can place as many diagnostics on one line as you wish. To make the code |
| 45 | // more readable, you can use slash-newline to separate out the diagnostics. |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 46 | // |
| 47 | // The simple syntax above allows each specification to match exactly one error. |
| 48 | // You can use the extended syntax to customize this. The extended syntax is |
| 49 | // "expected-<type> <n> {{diag text}}", where <type> is one of "error", |
| 50 | // "warning" or "note", and <n> is a positive integer. This allows the |
| 51 | // diagnostic to appear as many times as specified. Example: |
| 52 | // |
| 53 | // void f(); // expected-note 2 {{previous declaration is here}} |
| 54 | // |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 55 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 56 | /// FindDiagnostics - Go through the comment and see if it indicates expected |
| 57 | /// diagnostics. If so, then put them in a diagnostic list. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 58 | /// |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 59 | static void FindDiagnostics(const char *CommentStart, unsigned CommentLen, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 60 | DiagList &ExpectedDiags, |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 61 | Preprocessor &PP, SourceLocation Pos, |
| 62 | const char *ExpectedStr) { |
| 63 | const char *CommentEnd = CommentStart+CommentLen; |
| 64 | unsigned ExpectedStrLen = strlen(ExpectedStr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 65 | |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 66 | // Find all expected-foo diagnostics in the string and add them to |
| 67 | // ExpectedDiags. |
| 68 | while (CommentStart != CommentEnd) { |
| 69 | CommentStart = std::find(CommentStart, CommentEnd, 'e'); |
| 70 | if (unsigned(CommentEnd-CommentStart) < ExpectedStrLen) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 71 | |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 72 | // If this isn't expected-foo, ignore it. |
| 73 | if (memcmp(CommentStart, ExpectedStr, ExpectedStrLen)) { |
| 74 | ++CommentStart; |
| 75 | continue; |
| 76 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 78 | CommentStart += ExpectedStrLen; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 79 | |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 80 | // Skip whitespace. |
| 81 | while (CommentStart != CommentEnd && |
| 82 | isspace(CommentStart[0])) |
| 83 | ++CommentStart; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 84 | |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 85 | // Default, if we find the '{' now, is 1 time. |
| 86 | int Times = 1; |
| 87 | int Temp = 0; |
| 88 | // In extended syntax, there could be a digit now. |
| 89 | while (CommentStart != CommentEnd && |
| 90 | CommentStart[0] >= '0' && CommentStart[0] <= '9') { |
| 91 | Temp *= 10; |
| 92 | Temp += CommentStart[0] - '0'; |
| 93 | ++CommentStart; |
| 94 | } |
| 95 | if (Temp > 0) |
| 96 | Times = Temp; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 97 | |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 98 | // Skip whitespace again. |
| 99 | while (CommentStart != CommentEnd && |
| 100 | isspace(CommentStart[0])) |
| 101 | ++CommentStart; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 103 | // We should have a {{ now. |
| 104 | if (CommentEnd-CommentStart < 2 || |
| 105 | CommentStart[0] != '{' || CommentStart[1] != '{') { |
| 106 | if (std::find(CommentStart, CommentEnd, '{') != CommentEnd) |
| 107 | EmitError(PP, Pos, "bogus characters before '{{' in expected string"); |
| 108 | else |
| 109 | EmitError(PP, Pos, "cannot find start ('{{') of expected string"); |
Chris Lattner | b2c8c55 | 2008-11-23 23:38:26 +0000 | [diff] [blame] | 110 | return; |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 111 | } |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 112 | CommentStart += 2; |
| 113 | |
| 114 | // Find the }}. |
| 115 | const char *ExpectedEnd = CommentStart; |
| 116 | while (1) { |
| 117 | ExpectedEnd = std::find(ExpectedEnd, CommentEnd, '}'); |
| 118 | if (CommentEnd-ExpectedEnd < 2) { |
| 119 | EmitError(PP, Pos, "cannot find end ('}}') of expected string"); |
| 120 | return; |
| 121 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 122 | |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 123 | if (ExpectedEnd[1] == '}') |
| 124 | break; |
| 125 | |
| 126 | ++ExpectedEnd; // Skip over singular }'s |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 129 | std::string Msg(CommentStart, ExpectedEnd); |
| 130 | std::string::size_type FindPos; |
Chris Lattner | b2c8c55 | 2008-11-23 23:38:26 +0000 | [diff] [blame] | 131 | while ((FindPos = Msg.find("\\n")) != std::string::npos) |
Sebastian Redl | ad3c91c | 2008-10-26 19:05:16 +0000 | [diff] [blame] | 132 | Msg.replace(FindPos, 2, "\n"); |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 133 | // Add is possibly multiple times. |
| 134 | for (int i = 0; i < Times; ++i) |
| 135 | ExpectedDiags.push_back(std::make_pair(Pos, Msg)); |
| 136 | |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 137 | CommentStart = ExpectedEnd; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
Ted Kremenek | 95041a2 | 2007-12-19 22:51:13 +0000 | [diff] [blame] | 141 | /// FindExpectedDiags - Lex the main source file to find all of the |
| 142 | // expected errors and warnings. |
| 143 | static void FindExpectedDiags(Preprocessor &PP, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 144 | DiagList &ExpectedErrors, |
Douglas Gregor | 233f74b | 2008-09-11 02:46:36 +0000 | [diff] [blame] | 145 | DiagList &ExpectedWarnings, |
| 146 | DiagList &ExpectedNotes) { |
Chris Lattner | a39f048 | 2008-11-21 01:18:36 +0000 | [diff] [blame] | 147 | // Create a raw lexer to pull all the comments out of the main file. We don't |
| 148 | // want to look in #include'd headers for expected-error strings. |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 149 | FileID FID = PP.getSourceManager().getMainFileID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Chris Lattner | a39f048 | 2008-11-21 01:18:36 +0000 | [diff] [blame] | 151 | // Create a lexer to lex all the tokens of the main file in raw mode. |
Chris Lattner | 6e29014 | 2009-11-30 04:18:44 +0000 | [diff] [blame] | 152 | const llvm::MemoryBuffer *FromFile = PP.getSourceManager().getBuffer(FID); |
| 153 | Lexer RawLex(FID, FromFile, PP.getSourceManager(), PP.getLangOptions()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 154 | |
Chris Lattner | a39f048 | 2008-11-21 01:18:36 +0000 | [diff] [blame] | 155 | // Return comments as tokens, this is how we find expected diagnostics. |
| 156 | RawLex.SetCommentRetentionState(true); |
| 157 | |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 158 | Token Tok; |
Chris Lattner | b2c8c55 | 2008-11-23 23:38:26 +0000 | [diff] [blame] | 159 | Tok.setKind(tok::comment); |
| 160 | while (Tok.isNot(tok::eof)) { |
Chris Lattner | a39f048 | 2008-11-21 01:18:36 +0000 | [diff] [blame] | 161 | RawLex.Lex(Tok); |
Chris Lattner | b2c8c55 | 2008-11-23 23:38:26 +0000 | [diff] [blame] | 162 | if (!Tok.is(tok::comment)) continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
Chris Lattner | b2c8c55 | 2008-11-23 23:38:26 +0000 | [diff] [blame] | 164 | std::string Comment = PP.getSpelling(Tok); |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 165 | if (Comment.empty()) continue; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 166 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | |
Chris Lattner | b2c8c55 | 2008-11-23 23:38:26 +0000 | [diff] [blame] | 168 | // Find all expected errors. |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 169 | FindDiagnostics(&Comment[0], Comment.size(), ExpectedErrors, PP, |
Chris Lattner | b2c8c55 | 2008-11-23 23:38:26 +0000 | [diff] [blame] | 170 | Tok.getLocation(), "expected-error"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 171 | |
Chris Lattner | b2c8c55 | 2008-11-23 23:38:26 +0000 | [diff] [blame] | 172 | // Find all expected warnings. |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 173 | FindDiagnostics(&Comment[0], Comment.size(), ExpectedWarnings, PP, |
Chris Lattner | b2c8c55 | 2008-11-23 23:38:26 +0000 | [diff] [blame] | 174 | Tok.getLocation(), "expected-warning"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 175 | |
Chris Lattner | b2c8c55 | 2008-11-23 23:38:26 +0000 | [diff] [blame] | 176 | // Find all expected notes. |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 177 | FindDiagnostics(&Comment[0], Comment.size(), ExpectedNotes, PP, |
Chris Lattner | b2c8c55 | 2008-11-23 23:38:26 +0000 | [diff] [blame] | 178 | Tok.getLocation(), "expected-note"); |
| 179 | }; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /// PrintProblem - This takes a diagnostic map of the delta between expected and |
| 183 | /// seen diagnostics. If there's anything in it, then something unexpected |
| 184 | /// happened. Print the map out in a nice format and return "true". If the map |
| 185 | /// is empty and we're not going to print things, then return "false". |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 186 | /// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 187 | static bool PrintProblem(SourceManager &SourceMgr, |
| 188 | const_diag_iterator diag_begin, |
| 189 | const_diag_iterator diag_end, |
| 190 | const char *Msg) { |
| 191 | if (diag_begin == diag_end) return false; |
| 192 | |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 193 | llvm::errs() << Msg << "\n"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 194 | for (const_diag_iterator I = diag_begin, E = diag_end; I != E; ++I) |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 195 | llvm::errs() << " Line " << SourceMgr.getInstantiationLineNumber(I->first) |
| 196 | << " " << I->second << "\n"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 197 | |
| 198 | return true; |
| 199 | } |
| 200 | |
Chris Lattner | 4e69fd5 | 2009-02-04 02:15:34 +0000 | [diff] [blame] | 201 | /// CompareDiagLists - Compare two diagnostic lists and return the difference |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 202 | /// between them. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 203 | /// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 204 | static bool CompareDiagLists(SourceManager &SourceMgr, |
| 205 | const_diag_iterator d1_begin, |
| 206 | const_diag_iterator d1_end, |
| 207 | const_diag_iterator d2_begin, |
| 208 | const_diag_iterator d2_end, |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 209 | const char *MsgLeftOnly, |
| 210 | const char *MsgRightOnly) { |
| 211 | DiagList LeftOnly; |
| 212 | DiagList Left(d1_begin, d1_end); |
| 213 | DiagList Right(d2_begin, d2_end); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 214 | |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 215 | for (const_diag_iterator I = Left.begin(), E = Left.end(); I != E; ++I) { |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 216 | unsigned LineNo1 = SourceMgr.getInstantiationLineNumber(I->first); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 217 | const std::string &Diag1 = I->second; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 218 | |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 219 | DiagList::iterator II, IE; |
| 220 | for (II = Right.begin(), IE = Right.end(); II != IE; ++II) { |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 221 | unsigned LineNo2 = SourceMgr.getInstantiationLineNumber(II->first); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 222 | if (LineNo1 != LineNo2) continue; |
| 223 | |
| 224 | const std::string &Diag2 = II->second; |
| 225 | if (Diag2.find(Diag1) != std::string::npos || |
| 226 | Diag1.find(Diag2) != std::string::npos) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 227 | break; |
| 228 | } |
| 229 | } |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 230 | if (II == IE) { |
| 231 | // Not found. |
| 232 | LeftOnly.push_back(*I); |
| 233 | } else { |
| 234 | // Found. The same cannot be found twice. |
| 235 | Right.erase(II); |
| 236 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 237 | } |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 238 | // Now all that's left in Right are those that were not matched. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 239 | |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 240 | return PrintProblem(SourceMgr, LeftOnly.begin(), LeftOnly.end(), MsgLeftOnly) |
| 241 | | PrintProblem(SourceMgr, Right.begin(), Right.end(), MsgRightOnly); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /// CheckResults - This compares the expected results to those that |
| 245 | /// were actually reported. It emits any discrepencies. Return "true" if there |
| 246 | /// were problems. Return "false" otherwise. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 247 | /// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 248 | static bool CheckResults(Preprocessor &PP, |
| 249 | const DiagList &ExpectedErrors, |
Douglas Gregor | 233f74b | 2008-09-11 02:46:36 +0000 | [diff] [blame] | 250 | const DiagList &ExpectedWarnings, |
| 251 | const DiagList &ExpectedNotes) { |
Nico Weber | 7bfaaae | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 252 | const DiagnosticClient *DiagClient = PP.getDiagnostics().getClient(); |
| 253 | assert(DiagClient != 0 && |
| 254 | "DiagChecker requires a valid TextDiagnosticBuffer"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 255 | const TextDiagnosticBuffer &Diags = |
Nico Weber | 7bfaaae | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 256 | static_cast<const TextDiagnosticBuffer&>(*DiagClient); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 257 | SourceManager &SourceMgr = PP.getSourceManager(); |
| 258 | |
| 259 | // We want to capture the delta between what was expected and what was |
| 260 | // seen. |
| 261 | // |
| 262 | // Expected \ Seen - set expected but not seen |
| 263 | // Seen \ Expected - set seen but not expected |
| 264 | bool HadProblem = false; |
| 265 | |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 266 | // See if there are error mismatches. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 267 | HadProblem |= CompareDiagLists(SourceMgr, |
| 268 | ExpectedErrors.begin(), ExpectedErrors.end(), |
| 269 | Diags.err_begin(), Diags.err_end(), |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 270 | "Errors expected but not seen:", |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 271 | "Errors seen but not expected:"); |
| 272 | |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 273 | // See if there are warning mismatches. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 274 | HadProblem |= CompareDiagLists(SourceMgr, |
| 275 | ExpectedWarnings.begin(), |
| 276 | ExpectedWarnings.end(), |
| 277 | Diags.warn_begin(), Diags.warn_end(), |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 278 | "Warnings expected but not seen:", |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 279 | "Warnings seen but not expected:"); |
| 280 | |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 281 | // See if there are note mismatches. |
Douglas Gregor | 233f74b | 2008-09-11 02:46:36 +0000 | [diff] [blame] | 282 | HadProblem |= CompareDiagLists(SourceMgr, |
| 283 | ExpectedNotes.begin(), |
| 284 | ExpectedNotes.end(), |
| 285 | Diags.note_begin(), Diags.note_end(), |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 286 | "Notes expected but not seen:", |
Douglas Gregor | 233f74b | 2008-09-11 02:46:36 +0000 | [diff] [blame] | 287 | "Notes seen but not expected:"); |
| 288 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 289 | return HadProblem; |
| 290 | } |
| 291 | |
Chris Lattner | 009e9f7 | 2007-08-10 18:27:41 +0000 | [diff] [blame] | 292 | |
Argyrios Kyrtzidis | 14d4140 | 2008-06-13 12:15:34 +0000 | [diff] [blame] | 293 | /// CheckDiagnostics - Gather the expected diagnostics and check them. |
| 294 | bool clang::CheckDiagnostics(Preprocessor &PP) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 295 | // Gather the set of expected diagnostics. |
Douglas Gregor | 233f74b | 2008-09-11 02:46:36 +0000 | [diff] [blame] | 296 | DiagList ExpectedErrors, ExpectedWarnings, ExpectedNotes; |
| 297 | FindExpectedDiags(PP, ExpectedErrors, ExpectedWarnings, ExpectedNotes); |
Ted Kremenek | 4457978 | 2007-09-25 18:37:20 +0000 | [diff] [blame] | 298 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 299 | // Check that the expected diagnostics occurred. |
Douglas Gregor | 233f74b | 2008-09-11 02:46:36 +0000 | [diff] [blame] | 300 | return CheckResults(PP, ExpectedErrors, ExpectedWarnings, ExpectedNotes); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 301 | } |