[clang] [Clang][CodeGen] Enable pointer overflow check for GCC workaround (PR #137849)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Wed May 7 12:24:59 PDT 2025


================
@@ -4169,10 +4169,10 @@ 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()))
+  // 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()))
----------------
efriedma-quic wrote:

We can do the overflow check; we just need to make sure we do the inttoptr afterwards, instead of the gep of null.

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


More information about the cfe-commits mailing list