https://github.com/StepfenShawn created https://github.com/llvm/llvm-project/pull/192051
Add a defensive null check for `getIdentifierInfo()` in `PreprocessingRecord::InclusionDirective` to prevent potential null pointer dereference. The function assumes the token has valid identifier info, but `getIdentifierInfo()` can return nullptr for literals or EOF tokens. From 080b4059b99669509ee1fb122ab43bfcb75af98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8D=8CShawn?= <[email protected]> Date: Tue, 14 Apr 2026 20:53:06 +0800 Subject: [PATCH] Add null check for IncludeTok in PreprocessingRecord.cpp --- clang/lib/Lex/PreprocessingRecord.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp index f76155b1c45d6..d0f09552a003b 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -473,7 +473,11 @@ void PreprocessingRecord::InclusionDirective( bool ModuleImported, SrcMgr::CharacteristicKind FileType) { InclusionDirective::InclusionKind Kind = InclusionDirective::Include; - switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) { + IdentifierInfo *II = IncludeTok.getIdentifierInfo(); + if (!II) + llvm_unreachable("Invalid include directive token"); + + switch (II->getPPKeywordID()) { case tok::pp_include: Kind = InclusionDirective::Include; break; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
