[clang] [Clang][CodeGen] Check `isUnderlyingBasePointerConstantNull` in `emitPointerArithmetic` (PR #137849)
Yingwei Zheng via cfe-commits
cfe-commits at lists.llvm.org
Thu May 1 03:48:24 PDT 2025
================
@@ -4238,7 +4238,8 @@ static Value *emitPointerArithmetic(CodeGenFunction &CGF,
else
elemTy = CGF.ConvertTypeForMem(elementType);
- if (CGF.getLangOpts().PointerOverflowDefined)
+ if (CGF.getLangOpts().PointerOverflowDefined ||
+ CGF.isUnderlyingBasePointerConstantNull(pointerOperand))
----------------
dtcxzyw wrote:
> while this case only drops the inbounds, but still keeps the gep null, resulting in a pointer with nullary provenance, so any loads/stores on it are UB.
Unfortunately, the result of `__PTR_ALIGN` will be used to perform memory access :(
https://github.com/gcc-mirror/gcc/blob/79aa2a283a8d3327ff4d6dca77e81d5b1ac3a01e/libiberty/obstack.c#L213-L218
So this workaround doesn't address the real issue...
https://github.com/llvm/llvm-project/pull/137849
More information about the cfe-commits
mailing list