[clang] [clang][Lex] Add null check for `IncludeTok` in `PreprocessingRecord::InclusionDirective` (PR #192051)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 14 08:10:05 PDT 2026
https://github.com/StepfenShawn updated https://github.com/llvm/llvm-project/pull/192051
>From 080b4059b99669509ee1fb122ab43bfcb75af98c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=F0=9F=8D=8CShawn?= <m18824909883 at 163.com>
Date: Tue, 14 Apr 2026 20:53:06 +0800
Subject: [PATCH 1/2] 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;
>From 36c41a4d97898994ea22145d93037d25317e91ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=F0=9F=8D=8CShawn?= <m18824909883 at 163.com>
Date: Tue, 14 Apr 2026 23:09:55 +0800
Subject: [PATCH 2/2] Replace llvm_unreachable with assert for include token
---
clang/lib/Lex/PreprocessingRecord.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp
index d0f09552a003b..99914c1353e1c 100644
--- a/clang/lib/Lex/PreprocessingRecord.cpp
+++ b/clang/lib/Lex/PreprocessingRecord.cpp
@@ -474,8 +474,7 @@ void PreprocessingRecord::InclusionDirective(
InclusionDirective::InclusionKind Kind = InclusionDirective::Include;
IdentifierInfo *II = IncludeTok.getIdentifierInfo();
- if (!II)
- llvm_unreachable("Invalid include directive token");
+ assert(II && "Invalid include directive token");
switch (II->getPPKeywordID()) {
case tok::pp_include:
More information about the cfe-commits
mailing list