[clang] [clang][Lex] Fix assertion on unclosed paren in PP directive (PR #234992)

Max Winkler via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 29 03:06:12 PDT 2026


================
@@ -581,6 +581,18 @@ TEST_F(LexerTest, AvoidPastEndOfStringDereference03) {
   EXPECT_TRUE(Lex("#include <\\\\\n").empty());
 }
 
+// Clangd uses single-file-parse mode in preamble scan on a truncated buffer.
+// An unclosed paren after an undefined identifier must not lex past the eod.
+TEST_F(LexerTest, SingleFileUnclosedParenUndefinedId01) {
+  PPOpts.SingleFileParseMode = true;
+  EXPECT_TRUE(Lex("#if (defined(FOO)\n").empty());
+}
+
+TEST_F(LexerTest, SingleFileUnclosedParenUndefinedId02) {
+  PPOpts.SingleFileParseMode = true;
+  EXPECT_TRUE(Lex("#if (FOO\n").empty());
----------------
max-winkler wrote:

This is a great idea. I replaced one of my tests with your one, which has the advantage that the line below the PP directive is lexed as well.

https://github.com/llvm/llvm-project/pull/234992


More information about the cfe-commits mailing list