Change -verify mode to find the "expected-error" and "expected-warning" strings
with a raw lexer instead of a PP lexer. This means that -verify doesn't scan #include'd headers for expected-error/warning strings, and it also means that it doesn't ignore them in #if 0. llvm-svn: 59774
This commit is contained in:
parent
473d76e81d
commit
fd384b1b3a
|
|
@ -93,28 +93,29 @@ static void FindExpectedDiags(Preprocessor &PP,
|
||||||
DiagList &ExpectedErrors,
|
DiagList &ExpectedErrors,
|
||||||
DiagList &ExpectedWarnings,
|
DiagList &ExpectedWarnings,
|
||||||
DiagList &ExpectedNotes) {
|
DiagList &ExpectedNotes) {
|
||||||
// Return comments as tokens, this is how we find expected diagnostics.
|
// Create a raw lexer to pull all the comments out of the main file. We don't
|
||||||
PP.SetCommentRetentionState(true, true);
|
// want to look in #include'd headers for expected-error strings.
|
||||||
|
|
||||||
// Enter the cave.
|
|
||||||
PP.EnterMainSourceFile();
|
|
||||||
|
|
||||||
// Turn off all warnings from relexing or preprocessing.
|
|
||||||
PP.getDiagnostics().setWarnOnExtensions(false);
|
|
||||||
PP.getDiagnostics().setErrorOnExtensions(false);
|
|
||||||
for (unsigned i = 0; i != diag::NUM_BUILTIN_DIAGNOSTICS; ++i)
|
|
||||||
if (PP.getDiagnostics().isBuiltinNoteWarningOrExtension((diag::kind)i))
|
|
||||||
PP.getDiagnostics().setDiagnosticMapping((diag::kind)i, diag::MAP_IGNORE);
|
|
||||||
|
|
||||||
|
unsigned FileID = PP.getSourceManager().getMainFileID();
|
||||||
|
std::pair<const char*,const char*> File =
|
||||||
|
PP.getSourceManager().getBufferData(FileID);
|
||||||
|
|
||||||
|
// Create a lexer to lex all the tokens of the main file in raw mode.
|
||||||
|
Lexer RawLex(SourceLocation::getFileLoc(FileID, 0),
|
||||||
|
PP.getLangOptions(), File.first, File.second);
|
||||||
|
|
||||||
|
// Return comments as tokens, this is how we find expected diagnostics.
|
||||||
|
RawLex.SetCommentRetentionState(true);
|
||||||
|
|
||||||
Token Tok;
|
Token Tok;
|
||||||
do {
|
do {
|
||||||
PP.Lex(Tok);
|
RawLex.Lex(Tok);
|
||||||
|
|
||||||
if (Tok.is(tok::comment)) {
|
if (Tok.is(tok::comment)) {
|
||||||
std::string Comment = PP.getSpelling(Tok);
|
std::string Comment = PP.getSpelling(Tok);
|
||||||
|
|
||||||
// Find all expected errors
|
// Find all expected errors
|
||||||
FindDiagnostics(Comment, ExpectedErrors,PP.getSourceManager(),
|
FindDiagnostics(Comment, ExpectedErrors, PP.getSourceManager(),
|
||||||
Tok.getLocation(), ExpectedErrStr);
|
Tok.getLocation(), ExpectedErrStr);
|
||||||
|
|
||||||
// Find all expected warnings
|
// Find all expected warnings
|
||||||
|
|
@ -126,8 +127,6 @@ static void FindExpectedDiags(Preprocessor &PP,
|
||||||
Tok.getLocation(), ExpectedNoteStr);
|
Tok.getLocation(), ExpectedNoteStr);
|
||||||
}
|
}
|
||||||
} while (Tok.isNot(tok::eof));
|
} while (Tok.isNot(tok::eof));
|
||||||
|
|
||||||
PP.SetCommentRetentionState(false, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// PrintProblem - This takes a diagnostic map of the delta between expected and
|
/// PrintProblem - This takes a diagnostic map of the delta between expected and
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@
|
||||||
// RUN: env CPATH="" clang -fsyntax-only -verify -DAS_SOURCE %s &&
|
// RUN: env CPATH="" clang -fsyntax-only -verify -DAS_SOURCE %s &&
|
||||||
// RUN: env CPATH="xyz:xyz" clang -fsyntax-only -verify -DAS_SOURCE %s &&
|
// RUN: env CPATH="xyz:xyz" clang -fsyntax-only -verify -DAS_SOURCE %s &&
|
||||||
// RUN: cd $(dirname %s) &&
|
// RUN: cd $(dirname %s) &&
|
||||||
// RUN: env CPATH="xyz::xyz" clang -fsyntax-only -verify -DSHOULD_FIND -DAS_SOURCE %s &&
|
// RUN: env CPATH="xyz::xyz" clang -fsyntax-only -verify -DSHOULD_FIND -DAS_SOURCE %s
|
||||||
// RUN: env CPATH="../Driver" clang -fsyntax-only -verify -DSHOULD_FIND -DAS_SOURCE %s
|
|
||||||
|
|
||||||
#ifdef AS_SOURCE
|
#ifdef AS_SOURCE
|
||||||
#undef AS_SOURCE
|
#undef AS_SOURCE
|
||||||
|
|
@ -12,16 +11,11 @@
|
||||||
|
|
||||||
#ifdef SHOULD_FIND
|
#ifdef SHOULD_FIND
|
||||||
#include <env-include-paths.c>
|
#include <env-include-paths.c>
|
||||||
#else
|
|
||||||
/* expected-error {{file not found}} */ #include <env-include-paths.c>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#undef AS_INCLUDE
|
#undef AS_INCLUDE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef AS_INCLUDE
|
|
||||||
|
|
||||||
/* expected-warning {{Hello}} */ #warning "Hello"
|
/* expected-warning {{Hello}} */ #warning "Hello"
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue