[clang] [clang][Lex] Add null check for `IncludeTok` in `PreprocessingRecord::InclusionDirective` (PR #192051)

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 15 08:29:30 PDT 2026


StepfenShawn wrote:

@yronglin  Thanks for the review! I think there may be a misunderstanding about the intent of this patch — let me clarify.

This is not a fix for a known crash. There is no existing reproducer, and that's intentional.

The current call sites always pass a valid directive token, so `getIdentifierInfo()` never returns `nullptr` today. The patch is a defensive hardening change, not a bug fix. My purpose is to:

* Make the implicit assumption explicit — the code currently silently assumes `getIdentifierInfo()` is non-null. The assert documents this contract clearly for future readers and contributors.
* Catch regressions early — if a future caller (e.g., a new preprocessor hook, a plugin, or a refactor) accidentally passes an invalid token, the assert will fire immediately at the call site with a clear message, rather than causing a hard-to-diagnose null pointer dereference deep in a `switch` statement.

This pattern is common in LLVM/Clang for documenting and enforcing API contracts. 

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


More information about the cfe-commits mailing list