[llvm] [InstSimplify] Fold `getelementptr inbounds null, idx -> null` (PR #130742)
James Y Knight via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 28 07:54:53 PDT 2025
jyknight wrote:
This change breaks glibc's obstack.h, which is commonly-used in a bunch of software.
In particular, the file defines (for internal use) a [__PTR_ALIGN macro](https://github.com/bminor/glibc/blob/77930e0447e0b37a129db0e13c6c6f5e60a3019e/malloc/obstack.h#L119) which effectively expands
```__PTR_ALIGN(base, pointer, align_mask)```
to
```
((sizeof(long int) < sizeof(void *) ? (base) : (char *)0) +
(((pointer) - (sizeof(long int) < sizeof(void *) ? (base) : (char *)0) +
(align_mask)) &
~(align_mask)));
```
After simplifying, this is just, `(char *)0 + ((pointer - (char *)0 + align_mask) & ~align_mask);` -- which would be handled by the frontend special case in https://github.com/llvm/llvm-project/commit/3d0a540857edbd510e329f40581f6b2c1968ccca except that, unfortunately, when the addition to 0 is hidden by the ternary, the frontend special-case doesn't trigger.
The obstack code was fixed upstream in gnulib in 2023, via https://github.com/coreutils/gnulib/commit/e7cd5fb11f665d9e27f01d54672675199cd57f2d. Unfortunately, that hasn't made it back into glibc yet, even in ToT, nevermind releases. Also unfortunately, everyone copies this code into their own packages, so even fixing glibc doesn't solve the ecosystem issue. (I see at least binutils, bison, coreutils, dpkg, gettext, git, grep, m4, newlib, sed, and tar have private copies).
(I note that git independently fixed the issue in their copy of the file back in 2020, https://github.com/git/git/commit/cf82bff73f11d3197aa6b667002ea86da1dfa835.)
I think we probably should revert this change, even though it is correct. :(
https://github.com/llvm/llvm-project/pull/130742
More information about the llvm-commits
mailing list