]> granicus.if.org Git - clang/commit
[Lex] Fix crash on code completion in comment in included file.
authorVolodymyr Sapsai <vsapsai@apple.com>
Fri, 19 Jan 2018 23:41:47 +0000 (23:41 +0000)
committerVolodymyr Sapsai <vsapsai@apple.com>
Fri, 19 Jan 2018 23:41:47 +0000 (23:41 +0000)
commitd0ace12cca7588a88dbc5f3b4ef540fd0a634ef6
tree6d049819171ea29df7fa8a88e3d6bb0158b250b5
parent5d89c44ccd0a3e1d3ea58b9e736efd6b2f37eb5e
[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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@323008 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Lex/PPCaching.cpp
lib/Lex/PPLexerChange.cpp
test/CodeCompletion/Inputs/comments.h [new file with mode: 0644]
test/CodeCompletion/comments.cpp [new file with mode: 0644]