[llvm-branch-commits] [cfe-branch] r311591 - Merging r311330:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Aug 23 12:56:39 PDT 2017


Author: hans
Date: Wed Aug 23 12:56:39 2017
New Revision: 311591

URL: http://llvm.org/viewvc/llvm-project?rev=311591&view=rev
Log:
Merging r311330:
------------------------------------------------------------------------
r311330 | ibiryukov | 2017-08-21 05:03:08 -0700 (Mon, 21 Aug 2017) | 16 lines

Fixed a crash on replaying Preamble's PP conditional stack.

Summary:
The crash occurs when the first token after a preamble is a macro
expansion.
Fixed by moving replayPreambleConditionalStack from Parser into
Preprocessor. It is now called right after the predefines file is
processed.

Reviewers: erikjv, bkramer, klimek, yvvan

Reviewed By: bkramer

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D36872
------------------------------------------------------------------------

Added:
    cfe/branches/release_50/test/Index/preamble-conditionals-crash.cpp
      - copied unchanged from r311330, cfe/trunk/test/Index/preamble-conditionals-crash.cpp
    cfe/branches/release_50/test/Index/preamble-conditionals.cpp
      - copied unchanged from r311330, cfe/trunk/test/Index/preamble-conditionals.cpp
Modified:
    cfe/branches/release_50/   (props changed)
    cfe/branches/release_50/include/clang/Lex/Preprocessor.h
    cfe/branches/release_50/lib/Lex/PPLexerChange.cpp
    cfe/branches/release_50/lib/Lex/Preprocessor.cpp
    cfe/branches/release_50/lib/Parse/Parser.cpp

Propchange: cfe/branches/release_50/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Aug 23 12:56:39 2017
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:308455,308722,308824,308897,308996,309054,309058,309112-309113,309226,309263,309327,309382-309383,309488,309503,309523,309569,309607,309633,309636,309640,309722,309752,309975,310006,310158,310191,310359,310516,310672,310691-310692,310694,310700,310704,310706,310776,310804,310829,310983,311115,311182,311391,311397,311443,311532
+/cfe/trunk:308455,308722,308824,308897,308996,309054,309058,309112-309113,309226,309263,309327,309382-309383,309488,309503,309523,309569,309607,309633,309636,309640,309722,309752,309975,310006,310158,310191,310359,310516,310672,310691-310692,310694,310700,310704,310706,310776,310804,310829,310983,311115,311182,311330,311391,311397,311443,311532
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_50/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/include/clang/Lex/Preprocessor.h?rev=311591&r1=311590&r2=311591&view=diff
==============================================================================
--- cfe/branches/release_50/include/clang/Lex/Preprocessor.h (original)
+++ cfe/branches/release_50/include/clang/Lex/Preprocessor.h Wed Aug 23 12:56:39 2017
@@ -1048,10 +1048,6 @@ public:
   /// which implicitly adds the builtin defines etc.
   void EnterMainSourceFile();
 
-  /// \brief After parser warm-up, initialize the conditional stack from
-  /// the preamble.
-  void replayPreambleConditionalStack();
-
   /// \brief Inform the preprocessor callbacks that processing is complete.
   void EndSourceFile();
 
@@ -2025,6 +2021,10 @@ public:
   }
 
 private:
+  /// \brief After processing predefined file, initialize the conditional stack from
+  /// the preamble.
+  void replayPreambleConditionalStack();
+
   // Macro handling.
   void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterTopLevelIfndef);
   void HandleUndefDirective();

Modified: cfe/branches/release_50/lib/Lex/PPLexerChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/Lex/PPLexerChange.cpp?rev=311591&r1=311590&r2=311591&view=diff
==============================================================================
--- cfe/branches/release_50/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/branches/release_50/lib/Lex/PPLexerChange.cpp Wed Aug 23 12:56:39 2017
@@ -458,10 +458,16 @@ bool Preprocessor::HandleEndOfFile(Token
       SourceMgr.setNumCreatedFIDsForFileID(CurPPLexer->getFileID(), NumFIDs);
     }
 
+    bool ExitedFromPredefinesFile = false;
     FileID ExitedFID;
-    if (Callbacks && !isEndOfMacro && CurPPLexer)
+    if (!isEndOfMacro && CurPPLexer) {
       ExitedFID = CurPPLexer->getFileID();
 
+      assert(PredefinesFileID.isValid() &&
+             "HandleEndOfFile is called before PredefinesFileId is set");
+      ExitedFromPredefinesFile = (PredefinesFileID == ExitedFID);
+    }
+
     if (LeavingSubmodule) {
       // We're done with this submodule.
       Module *M = LeaveSubmodule(/*ForPragma*/false);
@@ -489,6 +495,11 @@ bool Preprocessor::HandleEndOfFile(Token
                              PPCallbacks::ExitFile, FileType, ExitedFID);
     }
 
+    // Restore conditional stack from the preamble right after exiting from the
+    // predefines file.
+    if (ExitedFromPredefinesFile)
+      replayPreambleConditionalStack();
+
     // Client should lex another token unless we generated an EOM.
     return LeavingSubmodule;
   }

Modified: cfe/branches/release_50/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/Lex/Preprocessor.cpp?rev=311591&r1=311590&r2=311591&view=diff
==============================================================================
--- cfe/branches/release_50/lib/Lex/Preprocessor.cpp (original)
+++ cfe/branches/release_50/lib/Lex/Preprocessor.cpp Wed Aug 23 12:56:39 2017
@@ -540,6 +540,8 @@ void Preprocessor::EnterMainSourceFile()
 void Preprocessor::replayPreambleConditionalStack() {
   // Restore the conditional stack from the preamble, if there is one.
   if (PreambleConditionalStack.isReplaying()) {
+    assert(CurPPLexer &&
+           "CurPPLexer is null when calling replayPreambleConditionalStack.");
     CurPPLexer->setConditionalLevels(PreambleConditionalStack.getStack());
     PreambleConditionalStack.doneReplaying();
   }

Modified: cfe/branches/release_50/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/Parse/Parser.cpp?rev=311591&r1=311590&r2=311591&view=diff
==============================================================================
--- cfe/branches/release_50/lib/Parse/Parser.cpp (original)
+++ cfe/branches/release_50/lib/Parse/Parser.cpp Wed Aug 23 12:56:39 2017
@@ -516,8 +516,6 @@ void Parser::Initialize() {
 
   // Prime the lexer look-ahead.
   ConsumeToken();
-
-  PP.replayPreambleConditionalStack();
 }
 
 void Parser::LateTemplateParserCleanupCallback(void *P) {




More information about the llvm-branch-commits mailing list