[cfe-commits] r66961 - in /cfe/trunk: include/clang/Lex/Preprocessor.h lib/Rewrite/HTMLRewrite.cpp test/Misc/emit-html.c
Chris Lattner
sabre at nondot.org
Fri Mar 13 14:44:46 PDT 2009
Author: lattner
Date: Fri Mar 13 16:44:46 2009
New Revision: 66961
URL: http://llvm.org/viewvc/llvm-project?rev=66961&view=rev
Log:
fix PR3798 by ignoring all diagnostics generated while repreprocessing a file in rewrite macros.
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
cfe/trunk/test/Misc/emit-html.c
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=66961&r1=66960&r2=66961&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri Mar 13 16:44:46 2009
@@ -197,6 +197,9 @@
~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; }
Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=66961&r1=66960&r2=66961&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Fri Mar 13 16:44:46 2009
@@ -424,6 +424,17 @@
}
}
+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 @@
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 @@
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,
Modified: cfe/trunk/test/Misc/emit-html.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/emit-html.c?rev=66961&r1=66960&r2=66961&view=diff
==============================================================================
--- cfe/trunk/test/Misc/emit-html.c (original)
+++ cfe/trunk/test/Misc/emit-html.c Fri Mar 13 16:44:46 2009
@@ -9,3 +9,10 @@
return F(argc, 1);
}
+// PR3798
+#define FOR_ALL_FILES(f,i) i
+
+#if 0
+ FOR_ALL_FILES(f) { }
+#endif
+
More information about the cfe-commits
mailing list