From de1a29277e122a72085ad7f3f5cd76baec010970 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Fri, 8 Jun 2012 18:06:21 +0000 Subject: Disable _Pragma during HTML macro rewriting to keep from crashing. The preprocessor's handling of diagnostic push/pops is stateful, so encountering pragmas during a re-parse causes problems. HTMLRewrite already filters out normal # directives including #pragma, so it's clear it's not expected to be interpreting pragmas in this mode. This fix adds a flag to Preprocessor to explicitly disable pragmas. The "right" fix might be to separate pragma lexing from pragma parsing so that we can throw away pragmas like we do preprocessor directives, but right now it's important to get the fix in. Note that this has nothing to do with the "hack" of re-using the input preprocessor in HTMLRewrite. Even if we someday copy the preprocessor instead of re-using it, the copy would (and should) include the diagnostic level tables and have the same problems. llvm-svn: 158214 --- clang/lib/Rewrite/HTMLRewrite.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'clang/lib/Rewrite/HTMLRewrite.cpp') diff --git a/clang/lib/Rewrite/HTMLRewrite.cpp b/clang/lib/Rewrite/HTMLRewrite.cpp index dc39dde7ff1..e2da26fc80c 100644 --- a/clang/lib/Rewrite/HTMLRewrite.cpp +++ b/clang/lib/Rewrite/HTMLRewrite.cpp @@ -495,6 +495,11 @@ void html::HighlightMacros(Rewriter &R, FileID FID, const Preprocessor& PP) { // Inform the preprocessor that we don't want comments. TmpPP.SetCommentRetentionState(false, false); + // We don't want pragmas either. Although we filtered out #pragma, removing + // _Pragma and __pragma is much harder. + bool PragmasPreviouslyEnabled = TmpPP.getPragmasEnabled(); + TmpPP.setPragmasEnabled(false); + // Enter the tokens we just lexed. This will cause them to be macro expanded // but won't enter sub-files (because we removed #'s). TmpPP.EnterTokenStream(&TokenStream[0], TokenStream.size(), false, false); @@ -571,6 +576,7 @@ void html::HighlightMacros(Rewriter &R, FileID FID, const Preprocessor& PP) { "", Expansion.c_str()); } - // Restore diagnostics object back to its own thing. + // Restore the preprocessor's old state. TmpPP.setDiagnostics(*OldDiags); + TmpPP.setPragmasEnabled(PragmasPreviouslyEnabled); } -- cgit v1.2.3