[PATCH] D102069: [clang][PreProcessor] Cutoff parsing after hitting completion point

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 7 06:27:21 PDT 2021


kadircet created this revision.
kadircet added a reviewer: hokein.
kadircet requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This fixes a crash caused by Lexers being invalidated at code
completion points in
https://github.com/llvm/llvm-project/blob/main/clang/lib/Lex/PPLexerChange.cpp#L520.


Repository:
  rG LLVM Github Monorepo

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,3 @@
+#define FOO(X) X + 1
+#if FOO(
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:2:9 %s | FileCheck %s --allow-empty
Index: clang/lib/Lex/PPDirectives.cpp
===================================================================
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -3023,6 +3023,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 evulating
+  // 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.343665.patch
Type: text/x-patch
Size: 981 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210507/6d25c838/attachment.bin>


More information about the cfe-commits mailing list