[clang] [NFC][Clang][Lex] Add assert to prevent null pointer dereference in Preprocessor::HandleModuleContextualKeyword (PR #211117)
Ian Li via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 23 08:08:20 PDT 2026
https://github.com/ianayl updated https://github.com/llvm/llvm-project/pull/211117
>From 948076a3d93f442975b152d45bb4029d8e20c40f Mon Sep 17 00:00:00 2001
From: "Li, Ian" <ian.li at intel.com>
Date: Tue, 21 Jul 2026 14:14:47 -0700
Subject: [PATCH 1/2] Add assert on CurPPLexer
---
clang/lib/Lex/Preprocessor.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 427a3826b299a..4bbf72ec9f611 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -1353,6 +1353,9 @@ bool Preprocessor::HandleModuleContextualKeyword(Token &Result) {
} else if (!Result.isAtPhysicalStartOfLine())
return false;
+ assert(CurPPLexer &&
+ "CurPPLexer is null when calling HandleModuleContextualKeyword.");
+
llvm::SaveAndRestore<bool> SavedParsingPreprocessorDirective(
CurPPLexer->ParsingPreprocessorDirective, true);
>From 29575ad141ce012f6c951eb1927832e4eaed9c1c Mon Sep 17 00:00:00 2001
From: Ian Li <ianayl.work at gmail.com>
Date: Thu, 23 Jul 2026 11:08:11 -0400
Subject: [PATCH 2/2] Update clang/lib/Lex/Preprocessor.cpp
Co-authored-by: Yihan Wang <yronglin777 at gmail.com>
---
clang/lib/Lex/Preprocessor.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 4bbf72ec9f611..bac84d1761a38 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -1354,7 +1354,7 @@ bool Preprocessor::HandleModuleContextualKeyword(Token &Result) {
return false;
assert(CurPPLexer &&
- "CurPPLexer is null when calling HandleModuleContextualKeyword.");
+ "CurPPLexer must not be null");
llvm::SaveAndRestore<bool> SavedParsingPreprocessorDirective(
CurPPLexer->ParsingPreprocessorDirective, true);
More information about the cfe-commits
mailing list