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?= <[email protected]> Date: Tue, 14 Apr 2026 20:53:06 +0800 Subject: [PATCH 1/4] 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?= <[email protected]> Date: Tue, 14 Apr 2026 23:09:55 +0800 Subject: [PATCH 2/4] 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: From f27d89ef473b525a16c42382745af13821f86e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8D=8CShawn?= <[email protected]> Date: Wed, 15 Apr 2026 20:05:51 +0800 Subject: [PATCH 3/4] Add test for inclusion directive --- clang/test/Lexer/pp-inclusion-directive.c | 8 ++++++++ clang/test/Lexer/pp-inclusion-directive.h | 1 + 2 files changed, 9 insertions(+) create mode 100644 clang/test/Lexer/pp-inclusion-directive.c create mode 100644 clang/test/Lexer/pp-inclusion-directive.h diff --git a/clang/test/Lexer/pp-inclusion-directive.c b/clang/test/Lexer/pp-inclusion-directive.c new file mode 100644 index 0000000000000..0cce9ace9aa83 --- /dev/null +++ b/clang/test/Lexer/pp-inclusion-directive.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fsyntax-only -detailed-preprocessing-record %s +// Test that PreprocessingRecord::InclusionDirective correctly handles various +// inclusion directive kinds (include, import, include_next). + +#include "pp-inclusion-directive.h" +#include <pp-inclusion-directive.h> +@import pp-inclusion-directive; +#include_next pp-inclusion-directive.h diff --git a/clang/test/Lexer/pp-inclusion-directive.h b/clang/test/Lexer/pp-inclusion-directive.h new file mode 100644 index 0000000000000..dbc3c8440097a --- /dev/null +++ b/clang/test/Lexer/pp-inclusion-directive.h @@ -0,0 +1 @@ +/* Header for pp-inclusion-directive.c test */ From 3a23d0ad6146b2aa1d552cda1b1b3603169ee29f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8D=8CShawn?= <[email protected]> Date: Wed, 15 Apr 2026 20:40:00 +0800 Subject: [PATCH 4/4] Move clang/test/Lexer/pp-inclusion-directive.h to clang/test/Lexer/Inputs/pp-inclusion-directive.h --- clang/test/Lexer/{ => Inputs}/pp-inclusion-directive.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename clang/test/Lexer/{ => Inputs}/pp-inclusion-directive.h (100%) diff --git a/clang/test/Lexer/pp-inclusion-directive.h b/clang/test/Lexer/Inputs/pp-inclusion-directive.h similarity index 100% rename from clang/test/Lexer/pp-inclusion-directive.h rename to clang/test/Lexer/Inputs/pp-inclusion-directive.h _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
