[clang] [Clang][CodeGen] Check `isUnderlyingBasePointerConstantNull` in `emitPointerArithmetic` (PR #137849)

Yingwei Zheng via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 29 22:18:31 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:

`BinaryOperator::isNullPointerArithmeticExtension` only allows the pointer operand to be a constant null. But `isUnderlyingBasePointerConstantNull` also catches `((struct S*)0)->field`.
I think it is safe to remove this workaround and fall through to the `isUnderlyingBasePointerConstantNull` check.


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


More information about the cfe-commits mailing list