[PATCH] D102069: [clang][PreProcessor] Cutoff parsing after hitting completion point
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 10 01:19:49 PDT 2021
kadircet updated this revision to Diff 343996.
kadircet added a comment.
- Fix lit
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102069/new/
https://reviews.llvm.org/D102069
Files:
clang/lib/Lex/PPDirectives.cpp
clang/test/CodeCompletion/crash-if-directive.cpp
Index: clang/test/CodeCompletion/crash-if-directive.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeCompletion/crash-if-directive.cpp
@@ -0,0 +1,6 @@
+#define FOO(X) X
+#if FOO(
+#elif FOO(
+#endif
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:2:9 %s
+// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:3:11 %s
Index: clang/lib/Lex/PPDirectives.cpp
===================================================================
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -595,6 +595,9 @@
CurPPLexer->LexingRawMode = false;
IdentifierInfo *IfNDefMacro = nullptr;
DirectiveEvalResult DER = EvaluateDirectiveExpression(IfNDefMacro);
+ // Stop if Lexer became invalid after hitting code completion token.
+ if (!CurPPLexer)
+ return;
const bool CondValue = DER.Conditional;
CurPPLexer->LexingRawMode = true;
if (Callbacks) {
@@ -3023,6 +3026,10 @@
IdentifierInfo *IfNDefMacro = nullptr;
const DirectiveEvalResult DER = EvaluateDirectiveExpression(IfNDefMacro);
const bool ConditionalTrue = DER.Conditional;
+ // Lexer might become invalid if we hit code completion point while evaluating
+ // expression.
+ if (!CurPPLexer)
+ return;
// If this condition is equivalent to #ifndef X, and if this is the first
// directive seen, handle it for the multiple-include optimization.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102069.343996.patch
Type: text/x-patch
Size: 1486 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210510/abe02fdb/attachment.bin>
More information about the cfe-commits
mailing list