diff options
author | Hans Wennborg <hans@hanshq.net> | 2018-01-24 15:28:43 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2018-01-24 15:28:43 +0000 |
commit | abf562a42defe561f4286a55b795369782c8a1a0 (patch) | |
tree | c04cd4002c3b8a3c035054d8bed04bfd7ace99cf | |
parent | 820d01f26dd1275bdf60f743d560b7e17d7b9178 (diff) |
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
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_60@323333 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Lex/PPCaching.cpp | 4 | ||||
-rw-r--r-- | lib/Lex/PPLexerChange.cpp | 1 | ||||
-rw-r--r-- | test/CodeCompletion/Inputs/comments.h | 4 | ||||
-rw-r--r-- | test/CodeCompletion/comments.cpp | 13 |
4 files changed, 21 insertions, 1 deletions
diff --git a/lib/Lex/PPCaching.cpp b/lib/Lex/PPCaching.cpp index f5e8cdc25d..9758557d7b 100644 --- a/lib/Lex/PPCaching.cpp +++ b/lib/Lex/PPCaching.cpp @@ -105,8 +105,10 @@ void Preprocessor::CachingLex(Token &Result) { } void Preprocessor::EnterCachingLexMode() { - if (InCachingLexMode()) + if (InCachingLexMode()) { + assert(CurLexerKind == CLK_CachingLexer && "Unexpected lexer kind"); return; + } PushIncludeMacroStack(); CurLexerKind = CLK_CachingLexer; diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp index e484e9c4c3..f21787338b 100644 --- a/lib/Lex/PPLexerChange.cpp +++ b/lib/Lex/PPLexerChange.cpp @@ -444,6 +444,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) { } CurPPLexer = nullptr; + recomputeCurLexerKind(); return true; } diff --git a/test/CodeCompletion/Inputs/comments.h b/test/CodeCompletion/Inputs/comments.h new file mode 100644 index 0000000000..7b4b5daa0b --- /dev/null +++ b/test/CodeCompletion/Inputs/comments.h @@ -0,0 +1,4 @@ +// PR32732 +struct B { + // <- code completion +}; diff --git a/test/CodeCompletion/comments.cpp b/test/CodeCompletion/comments.cpp new file mode 100644 index 0000000000..21f1465ebc --- /dev/null +++ b/test/CodeCompletion/comments.cpp @@ -0,0 +1,13 @@ +// Note: the run lines follow their respective tests, since line/column +// matter in this test. + +#include "comments.h" + +struct A { + // <- code completion + /* <- code completion */ +}; + +// RUN: %clang_cc1 -I %S/Inputs -fsyntax-only -code-completion-at=%s:7:6 %s +// RUN: %clang_cc1 -I %S/Inputs -fsyntax-only -code-completion-at=%s:8:6 %s +// RUN: %clang_cc1 -I %S/Inputs -fsyntax-only -code-completion-at=%S/Inputs/comments.h:3:6 %s |