[llvm-branch-commits] [cfe-branch] r323333 - Merging r323008:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 24 07:28:43 PST 2018


Author: hans
Date: Wed Jan 24 07:28:43 2018
New Revision: 323333

URL: http://llvm.org/viewvc/llvm-project?rev=323333&view=rev
Log:
Merging r323008:
------------------------------------------------------------------------
r323008 | vsapsai | 2018-01-20 00:41:47 +0100 (Sat, 20 Jan 2018) | 32 lines

[Lex] Fix crash on code completion in comment in included file.

This fixes PR32732 by updating CurLexerKind to reflect available lexers.
We were hitting null pointer in Preprocessor::Lex because CurLexerKind
was CLK_Lexer but CurLexer was null. And we set it to null in
Preprocessor::HandleEndOfFile when exiting a file with code completion
point.

To reproduce the crash it is important for a comment to be inside a
class specifier. In this case in Parser::ParseClassSpecifier we improve
error recovery by pushing a semicolon token back into the preprocessor
and later on try to lex a token because we haven't reached the end of
file.

Also clang crashes only on code completion in included file, i.e. when
IncludeMacroStack is not empty. Though we reset CurLexer even if include
stack is empty. The difference is that during pushing back a semicolon
token, preprocessor calls EnterCachingLexMode which decides it is
already in caching mode because various lexers are null and
IncludeMacroStack is not empty. As the result, CurLexerKind remains
CLK_Lexer instead of updating to CLK_CachingLexer.

rdar://problem/34787685

Reviewers: akyrtzi, doug.gregor, arphaman

Reviewed By: arphaman

Subscribers: cfe-commits, kfunk, arphaman, nemanjai, kbarton

Differential Revision: https://reviews.llvm.org/D41688

------------------------------------------------------------------------

Added:
    cfe/branches/release_60/test/CodeCompletion/Inputs/comments.h
      - copied unchanged from r323008, cfe/trunk/test/CodeCompletion/Inputs/comments.h
    cfe/branches/release_60/test/CodeCompletion/comments.cpp
      - copied unchanged from r323008, cfe/trunk/test/CodeCompletion/comments.cpp
Modified:
    cfe/branches/release_60/   (props changed)
    cfe/branches/release_60/lib/Lex/PPCaching.cpp
    cfe/branches/release_60/lib/Lex/PPLexerChange.cpp

Propchange: cfe/branches/release_60/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 24 07:28:43 2018
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:321754,321771,321777,321779,321933,322018,322236,322246,322350,322390,322405,322420,322518,322593,322813,322901,322904,322984,323123
+/cfe/trunk:321754,321771,321777,321779,321933,322018,322236,322246,322350,322390,322405,322420,322518,322593,322813,322901,322904,322984,323008,323123
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_60/lib/Lex/PPCaching.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/lib/Lex/PPCaching.cpp?rev=323333&r1=323332&r2=323333&view=diff
==============================================================================
--- cfe/branches/release_60/lib/Lex/PPCaching.cpp (original)
+++ cfe/branches/release_60/lib/Lex/PPCaching.cpp Wed Jan 24 07:28:43 2018
@@ -105,8 +105,10 @@ void Preprocessor::CachingLex(Token &Res
 }
 
 void Preprocessor::EnterCachingLexMode() {
-  if (InCachingLexMode())
+  if (InCachingLexMode()) {
+    assert(CurLexerKind == CLK_CachingLexer && "Unexpected lexer kind");
     return;
+  }
 
   PushIncludeMacroStack();
   CurLexerKind = CLK_CachingLexer;

Modified: cfe/branches/release_60/lib/Lex/PPLexerChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/lib/Lex/PPLexerChange.cpp?rev=323333&r1=323332&r2=323333&view=diff
==============================================================================
--- cfe/branches/release_60/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/branches/release_60/lib/Lex/PPLexerChange.cpp Wed Jan 24 07:28:43 2018
@@ -444,6 +444,7 @@ bool Preprocessor::HandleEndOfFile(Token
       }
 
       CurPPLexer = nullptr;
+      recomputeCurLexerKind();
       return true;
     }
 




More information about the llvm-branch-commits mailing list