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

Yingwei Zheng via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 12 19:08:52 PDT 2025


dtcxzyw wrote:

> I'd still prefer to get this right for all address-spaces, so we don't need to revisit later.

Sentinel pointer value support for non-0 address spaces is still work in progress: https://github.com/llvm/llvm-project/pull/83109 
I am ok to add a helper like `Address::isConstantNull` if needed.

> But really, I'm more concerned about the "happens to get folded" part: there isn't a stable set of values that get constant-folded, at the LLVM IR level, it's just whether IRBuilder happens to do today. 

I don't expect it to work on more complex patterns like `(int*)(x-x)`.

> The only way to get a stable answer is to query the AST (Expr::isNullPointerConstant).

`Expr::isNullPointerConstant` is unavailable in clang CodeGen unless we store the result into `Address`.


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


More information about the cfe-commits mailing list