[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
llvm-svn: 153994
diff --git a/clang/lib/Lex/PPCaching.cpp b/clang/lib/Lex/PPCaching.cpp
index 0d5e34f..6f4c189 100644
--- a/clang/lib/Lex/PPCaching.cpp
+++ b/clang/lib/Lex/PPCaching.cpp
@@ -57,17 +57,21 @@
ExitCachingLexMode();
Lex(Result);
- if (!isBacktrackEnabled()) {
- // All cached tokens were consumed.
- CachedTokens.clear();
- CachedLexPos = 0;
+ if (isBacktrackEnabled()) {
+ // Cache the lexed token.
+ EnterCachingLexMode();
+ CachedTokens.push_back(Result);
+ ++CachedLexPos;
return;
}
- // Cache the lexed token.
- EnterCachingLexMode();
- CachedTokens.push_back(Result);
- ++CachedLexPos;
+ if (CachedLexPos < CachedTokens.size()) {
+ EnterCachingLexMode();
+ } else {
+ // All cached tokens were consumed.
+ CachedTokens.clear();
+ CachedLexPos = 0;
+ }
}
void Preprocessor::EnterCachingLexMode() {