[clang] [Clang][CodeGen] Do not set inbounds flag for struct GEP with null base pointers (PR #130734)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 20 06:53:50 PDT 2025


AaronBallman wrote:

> Needs release note.
> 
> The big thing I'm not sure about is whether we want a corresponding warning. We're detecting a pattern we know has undefined behavior, so we should maybe warn? CC @AaronBallman @erichkeane

This pattern is undefined behavior, but we're wanting to define the behavior in this one specific case. My preference is to be honest about that: add documentation to `clang/docs/LanguageExtensions.rst` saying that we define the behavior of dereferencing a null pointer constant in these specific circumstances (and be clear that it's UB in all other circumstances), issue a pedantic warning about the extension, and make sure we have enough test coverage to help us avoid regressing the extension in the future. Bonus points if the pedantic warning comes with a fixit that suggest `offsetof` (not `__builtin_offsetof` because that's still an extension), but I don't think it's strictly required (fixits that require including a header file might be tricky?).

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


More information about the cfe-commits mailing list