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