[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 02:31:14 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG761f3d16753e: [clang][PreProcessor] Cutoff parsing after hitting completion point (authored by kadircet).
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.344010.patch
Type: text/x-patch
Size: 1486 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210510/a024aa72/attachment-0001.bin>
More information about the cfe-commits
mailing list