[clang] [Clang][CodeGen] Do not set inbounds flag for struct GEP with null base pointers (PR #130734)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 27 14:52:35 PDT 2025
================
@@ -42,6 +42,11 @@ Potentially Breaking Changes
C/C++ Language Potentially Breaking Changes
-------------------------------------------
+- Some old-style offsetof idioms like ``((int)(&(((struct S *)0)->field)))`` are treated
----------------
efriedma-quic wrote:
I was thinking something more like:
New LLVM optimizations have been implemented that optimize pointer arithmetic on null pointers more aggressively. As part of this, clang has implemented a special case for old-style offsetof idioms like ``((int)(&(((struct S *)0)->field)))``, to ensure they are not caught by these optimizations. It is also possible to use ``-fwrapv-pointer`` or ``-fno-delete-null-pointer-checks`` to make pointer arithmetic on null pointers well-defined. (#GH130734, #GH130742)
------
(Also -fwrapv-pointer doesn't actually work at the moment for the address computation associated with member access.)
https://github.com/llvm/llvm-project/pull/130734
More information about the cfe-commits
mailing list