[clang] [clang][CodeGen] Use ptrtoaddr for the pointer-overflow check (PR #223446)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 18 16:50:32 PDT 2026


================
@@ -6378,10 +6378,8 @@ static GEPOffsetAndOverflow EmitGEPOffsetInBytes(Value *BasePtr, Value *GEPVal,
   if (isa<llvm::Constant>(GEPVal)) {
     // Compute the offset by casting both pointers to integers and subtracting:
     // GEPVal = BasePtr + ptr(Offset) <--> Offset = int(GEPVal) - int(BasePtr)
-    Value *BasePtr_int =
-        Builder.CreatePtrToInt(BasePtr, DL.getIntPtrType(BasePtr->getType()));
-    Value *GEPVal_int =
-        Builder.CreatePtrToInt(GEPVal, DL.getIntPtrType(GEPVal->getType()));
+    Value *BasePtr_int = Builder.CreatePtrToAddr(BasePtr);
+    Value *GEPVal_int = Builder.CreatePtrToAddr(GEPVal);
----------------
efriedma-quic wrote:

Sure, that's fine.

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


More information about the cfe-commits mailing list