r305940 - [preprocessor] Fix assertion hit when 'SingleFileParseMode' option is enabled and #if with an undefined identifier and without #else

Argyrios Kyrtzidis via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 21 11:52:44 PDT 2017


Author: akirtzidis
Date: Wed Jun 21 13:52:44 2017
New Revision: 305940

URL: http://llvm.org/viewvc/llvm-project?rev=305940&view=rev
Log:
[preprocessor] Fix assertion hit when 'SingleFileParseMode' option is enabled and #if with an undefined identifier and without #else

'HandleEndifDirective' asserts that 'WasSkipping' is false, so switch to using 'FoundNonSkip' as the hint for 'SingleFileParseMode' to keep going with parsing.

Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/test/Index/single-file-parse.m

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=305940&r1=305939&r2=305940&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Jun 21 13:52:44 2017
@@ -2658,7 +2658,7 @@ void Preprocessor::HandleIfdefDirective(
     // 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(Tok
   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(T
   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(T
                     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;
   }

Modified: cfe/trunk/test/Index/single-file-parse.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/single-file-parse.m?rev=305940&r1=305939&r2=305940&view=diff
==============================================================================
--- cfe/trunk/test/Index/single-file-parse.m (original)
+++ cfe/trunk/test/Index/single-file-parse.m Wed Jun 21 13:52:44 2017
@@ -109,3 +109,13 @@
 // CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test28
 @interface Test28 @end
 #endif
+
+#if SOMETHING_NOT_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test29
+ at interface Test29 @end
+#endif
+
+#ifdef SOMETHING_NOT_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test30
+ at interface Test30 @end
+#endif




More information about the cfe-commits mailing list