[preprocessor] Fix assertion hit when 'SingleFileParseMode' option is enabled and...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 21 Jun 2017 18:52:44 +0000 (18:52 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 21 Jun 2017 18:52:44 +0000 (18:52 +0000)
'HandleEndifDirective' asserts that 'WasSkipping' is false, so switch to using 'FoundNonSkip' as the hint for 'SingleFileParseMode' to keep going with parsing.

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

lib/Lex/PPDirectives.cpp
test/Index/single-file-parse.m

index 422bfc896875adf8745a55d499eee4ce28d9398a..8c79e50176e18adc488c5ade20482b6846479655 100644 (file)
@@ -2658,7 +2658,7 @@ void Preprocessor::HandleIfdefDirective(Token &Result, bool isIfndef,
     // In 'single-file-parse mode' undefined identifiers trigger parsing of all
     // the directive blocks.
     CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(),
-                                     /*wasskip*/true, /*foundnonskip*/false,
+                                     /*wasskip*/false, /*foundnonskip*/false,
                                      /*foundelse*/false);
   } else if (!MI == isIfndef) {
     // Yes, remember that we are inside a conditional, then lex the next token.
@@ -2705,7 +2705,7 @@ void Preprocessor::HandleIfDirective(Token &IfToken,
   if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) {
     // In 'single-file-parse mode' undefined identifiers trigger parsing of all
     // the directive blocks.
-    CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/true,
+    CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false,
                                      /*foundnonskip*/false, /*foundelse*/false);
   } else if (ConditionalTrue) {
     // Yes, remember that we are inside a conditional, then lex the next token.
@@ -2768,11 +2768,11 @@ void Preprocessor::HandleElseDirective(Token &Result) {
   if (Callbacks)
     Callbacks->Else(Result.getLocation(), CI.IfLoc);
 
-  if (PPOpts->SingleFileParseMode && CI.WasSkipping) {
+  if (PPOpts->SingleFileParseMode && !CI.FoundNonSkip) {
     // In 'single-file-parse mode' undefined identifiers trigger parsing of all
     // the directive blocks.
     CurPPLexer->pushConditionalLevel(CI.IfLoc, /*wasskip*/false,
-                                     /*foundnonskip*/true, /*foundelse*/true);
+                                     /*foundnonskip*/false, /*foundelse*/true);
     return;
   }
 
@@ -2811,10 +2811,10 @@ void Preprocessor::HandleElifDirective(Token &ElifToken) {
                     SourceRange(ConditionalBegin, ConditionalEnd),
                     PPCallbacks::CVK_NotEvaluated, CI.IfLoc);
 
-  if (PPOpts->SingleFileParseMode && CI.WasSkipping) {
+  if (PPOpts->SingleFileParseMode && !CI.FoundNonSkip) {
     // In 'single-file-parse mode' undefined identifiers trigger parsing of all
     // the directive blocks.
-    CurPPLexer->pushConditionalLevel(ElifToken.getLocation(), /*wasskip*/true,
+    CurPPLexer->pushConditionalLevel(ElifToken.getLocation(), /*wasskip*/false,
                                      /*foundnonskip*/false, /*foundelse*/false);
     return;
   }
index 6e2189c43ddb3beeb29ae0cb4bf3f86df32b101f..f75b9bd0ee544313b3ec813f8576337b9543824d 100644 (file)
 // CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test28
 @interface Test28 @end
 #endif
+
+#if SOMETHING_NOT_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test29
+@interface Test29 @end
+#endif
+
+#ifdef SOMETHING_NOT_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test30
+@interface Test30 @end
+#endif