r175840 - Preproceessor: fix #if skipping under -traditional-cpp.

Jordan Rose jordan_rose at apple.com
Thu Feb 21 16:32:00 PST 2013


Author: jrose
Date: Thu Feb 21 18:32:00 2013
New Revision: 175840

URL: http://llvm.org/viewvc/llvm-project?rev=175840&view=rev
Log:
Preproceessor: fix #if skipping under -traditional-cpp.

When parsing directives within skipped #if blocks, we don't want to retain
any whitespace. Previously we were just skipping comments, but it's not
possible to skip comments and retain other whitespace. This change matches
the usual behavior for parsing directives (i.e. the behavior outside of
skipped #if blocks).

<rdar://problem/13267695>

Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/test/Preprocessor/traditional-cpp.c

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=175840&r1=175839&r2=175840&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Thu Feb 21 18:32:00 2013
@@ -258,7 +258,7 @@ void Preprocessor::SkipExcludedCondition
     // directive mode.  Tell the lexer this so any newlines we see will be
     // converted into an EOD token (this terminates the macro).
     CurPPLexer->ParsingPreprocessorDirective = true;
-    if (CurLexer) CurLexer->SetCommentRetentionState(false);
+    if (CurLexer) CurLexer->SetKeepWhitespaceMode(false);
 
 
     // Read the next token, the directive flavor.

Modified: cfe/trunk/test/Preprocessor/traditional-cpp.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/traditional-cpp.c?rev=175840&r1=175839&r2=175840&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/traditional-cpp.c (original)
+++ cfe/trunk/test/Preprocessor/traditional-cpp.c Thu Feb 21 18:32:00 2013
@@ -62,3 +62,19 @@ bracket2(spaces)
 /* If this were working, this check would be on.
  * CHECK-NOT: {{^}}>>>  spaces  <<<{{$}}
  */
+
+
+/* Check that #if 0 blocks work as expected */
+#if 0
+#error "this is not an error"
+
+#if 1
+a b c in skipped block
+#endif
+
+/* Comments are whitespace too */
+
+#endif
+/* CHECK-NOT: {{^}}a b c in skipped block{{$}}
+ * CHECK-NOT: {{^}}/* Comments are whitespace too
+ */





More information about the cfe-commits mailing list