[cfe-commits] r153994 - in /cfe/trunk: lib/Lex/PPCaching.cpp test/Preprocessor/_Pragma-in-macro-arg.c

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Apr 3 19:57:02 PDT 2012


Author: akirtzidis
Date: Tue Apr  3 21:57:01 2012
New Revision: 153994

URL: http://llvm.org/viewvc/llvm-project?rev=153994&view=rev
Log:
[preprocessor] In Preprocessor::CachingLex() check whether there were more tokens
cached during the non-cached lex, otherwise we are going to drop them.

Fixes a bogus "_Pragma takes a parenthesized string literal" error when
expanding consecutive _Pragmas in a macro argument.

Part of rdar://11168596

Modified:
    cfe/trunk/lib/Lex/PPCaching.cpp
    cfe/trunk/test/Preprocessor/_Pragma-in-macro-arg.c

Modified: cfe/trunk/lib/Lex/PPCaching.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPCaching.cpp?rev=153994&r1=153993&r2=153994&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPCaching.cpp (original)
+++ cfe/trunk/lib/Lex/PPCaching.cpp Tue Apr  3 21:57:01 2012
@@ -57,17 +57,21 @@
   ExitCachingLexMode();
   Lex(Result);
 
-  if (!isBacktrackEnabled()) {
+  if (isBacktrackEnabled()) {
+    // Cache the lexed token.
+    EnterCachingLexMode();
+    CachedTokens.push_back(Result);
+    ++CachedLexPos;
+    return;
+  }
+
+  if (CachedLexPos < CachedTokens.size()) {
+    EnterCachingLexMode();
+  } else {
     // All cached tokens were consumed.
     CachedTokens.clear();
     CachedLexPos = 0;
-    return;
   }
-
-  // Cache the lexed token.
-  EnterCachingLexMode();
-  CachedTokens.push_back(Result);
-  ++CachedLexPos;
 }
 
 void Preprocessor::EnterCachingLexMode() {

Modified: cfe/trunk/test/Preprocessor/_Pragma-in-macro-arg.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/_Pragma-in-macro-arg.c?rev=153994&r1=153993&r2=153994&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/_Pragma-in-macro-arg.c (original)
+++ cfe/trunk/test/Preprocessor/_Pragma-in-macro-arg.c Tue Apr  3 21:57:01 2012
@@ -15,7 +15,7 @@
 // This should be ignored..
 INACTIVE(_Pragma("clang diagnostic ignored \"-Wconversion\""))
 
-#define IGNORE_CONV _Pragma("clang diagnostic ignored \"-Wconversion\"")
+#define IGNORE_CONV _Pragma("clang diagnostic ignored \"-Wconversion\"") _Pragma("clang diagnostic ignored \"-Wconversion\"")
 
 // ..as should this.
 INACTIVE(IGNORE_CONV)





More information about the cfe-commits mailing list