[clang] [UBSan] Fix assertion failure in EmitCheckedInBoundsGEP for constant-… (PR #191278)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 9 17:03:22 PDT 2026


================
@@ -6413,10 +6413,9 @@ CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type *ElemTy, Value *Ptr,
   GEPOffsetAndOverflow EvaluatedGEP =
       EmitGEPOffsetInBytes(Ptr, GEPVal, getLLVMContext(), CGM, Builder);
 
-  assert((!isa<llvm::Constant>(EvaluatedGEP.TotalOffset) ||
-          EvaluatedGEP.OffsetOverflows == Builder.getFalse()) &&
-         "If the offset got constant-folded, we don't expect that there was an "
-         "overflow.");
+  // Note: TotalOffset can be a constant even when the GEP is non-constant
+  // (e.g. runtime base pointer with constant index). In that case,
+  // OffsetOverflows may be true if the constant offset computation overflowed.
----------------
efriedma-quic wrote:

This comment is not wrong, I guess, but there's still a bug here: a few lines later we check `EvaluatedGEP.TotalOffset == Zero`.

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


More information about the cfe-commits mailing list