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

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Mon May 5 14:03:55 PDT 2025


================
@@ -4169,11 +4169,16 @@ static Value *emitPointerArithmetic(CodeGenFunction &CGF,
   //   The index is not pointer-sized.
   //   The pointer type is not byte-sized.
   //
-  if (BinaryOperator::isNullPointerArithmeticExtension(CGF.getContext(),
-                                                       op.Opcode,
-                                                       expr->getLHS(),
-                                                       expr->getRHS()))
-    return CGF.Builder.CreateIntToPtr(index, pointer->getType());
+  // Note that we do not suppress the pointer overflow check in this case.
+  if (!CGF.SanOpts.has(SanitizerKind::PointerOverflow) &&
+      BinaryOperator::isNullPointerArithmeticExtension(
+          CGF.getContext(), op.Opcode, expr->getLHS(), expr->getRHS())) {
+    // isUnderlyingBasePointerConstantNull returns true does not indicate that
+    // the base pointer is null.
----------------
efriedma-quic wrote:

In this context, I don't think we need the MemberExpr recursion?  Nobody is going to write `(&((struct S*)0)->y) + i`.

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


More information about the cfe-commits mailing list