aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-13 21:44:46 +0000
committerChris Lattner <sabre@nondot.org>2009-03-13 21:44:46 +0000
commit7c175fb196a2bc3dbc86ea3865c713e1875f3f6d (patch)
treef58c382a186b1f15c04de3ebf795b75add65e5fd
parent836040f9eafe862fb1607df5c30cd3df0c22c832 (diff)
fix PR3798 by ignoring all diagnostics generated while repreprocessing a file in rewrite macros.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66961 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Lex/Preprocessor.h3
-rw-r--r--lib/Rewrite/HTMLRewrite.cpp22
-rw-r--r--test/Misc/emit-html.c7
3 files changed, 32 insertions, 0 deletions
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h
index 28aad1a7bb..17e2c2f8a0 100644
--- a/include/clang/Lex/Preprocessor.h
+++ b/include/clang/Lex/Preprocessor.h
@@ -197,6 +197,9 @@ public:
~Preprocessor();
Diagnostic &getDiagnostics() const { return *Diags; }
+ void setDiagnostics(Diagnostic &D) { Diags = &D; }
+
+
const LangOptions &getLangOptions() const { return Features; }
TargetInfo &getTargetInfo() const { return Target; }
FileManager &getFileManager() const { return FileMgr; }
diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp
index 380f7da743..9bb5d7cfd3 100644
--- a/lib/Rewrite/HTMLRewrite.cpp
+++ b/lib/Rewrite/HTMLRewrite.cpp
@@ -424,6 +424,17 @@ void html::SyntaxHighlight(Rewriter &R, FileID FID, Preprocessor &PP) {
}
}
+namespace {
+/// IgnoringDiagClient - This is a diagnostic client that just ignores all
+/// diags.
+class IgnoringDiagClient : public DiagnosticClient {
+ void HandleDiagnostic(Diagnostic::Level DiagLevel,
+ const DiagnosticInfo &Info) {
+ // Just ignore it.
+ }
+};
+}
+
/// HighlightMacros - This uses the macro table state from the end of the
/// file, to re-expand macros and insert (into the HTML) information about the
/// macro expansions. This won't be perfectly perfect, but it will be
@@ -466,6 +477,14 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) {
if (Tok.is(tok::eof)) break;
}
+ // Temporarily change the diagnostics object so that we ignore any generated
+ // diagnostics from this pass.
+ IgnoringDiagClient TmpDC;
+ Diagnostic TmpDiags(&TmpDC);
+
+ Diagnostic *OldDiags = &PP.getDiagnostics();
+ PP.setDiagnostics(TmpDiags);
+
// Inform the preprocessor that we don't want comments.
PP.SetCommentRetentionState(false, false);
@@ -542,6 +561,9 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) {
HighlightRange(R, LLoc.first, LLoc.second,
"<span class='macro'>", Expansion.c_str());
}
+
+ // Restore diagnostics object back to its own thing.
+ PP.setDiagnostics(*OldDiags);
}
void html::HighlightMacros(Rewriter &R, FileID FID,
diff --git a/test/Misc/emit-html.c b/test/Misc/emit-html.c
index c4a184584b..8c6556e3e5 100644
--- a/test/Misc/emit-html.c
+++ b/test/Misc/emit-html.c
@@ -9,3 +9,10 @@ int main(int argc, char **argv) {
return F(argc, 1);
}
+// PR3798
+#define FOR_ALL_FILES(f,i) i
+
+#if 0
+ FOR_ALL_FILES(f) { }
+#endif
+