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.
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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits