]> granicus.if.org Git - clang/commitdiff
[preprocessor] In Preprocessor::CachingLex() check whether there were more tokens
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 4 Apr 2012 02:57:01 +0000 (02:57 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 4 Apr 2012 02:57:01 +0000 (02:57 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153994 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPCaching.cpp
test/Preprocessor/_Pragma-in-macro-arg.c

index 0d5e34f0bfecb56159b21e5995514bff86d3f383..6f4c189b4f6a8ad9799c59054cae78447738f9da 100644 (file)
@@ -57,17 +57,21 @@ void Preprocessor::CachingLex(Token &Result) {
   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() {
index 99a33a9e1b33baadb75e013e41ed84949a732c1d..2877bcb7bfe0f666e6667a6523b95df140a6e33d 100644 (file)
@@ -15,7 +15,7 @@ B(_Pragma("clang diagnostic ignored \"-Wparentheses\""))
 // 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)