[clang] [UBSan] Fix assertion failure in EmitCheckedInBoundsGEP for constant-… (PR #191278)
Adam Magier via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 20 12:56:47 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.
----------------
AdamMagierFOSS wrote:
I should maybe ask for clarification - I take it the bug you're referring to is the fact that we could skip emitting a check when the offset gets constant folded to zero, even if there was actually an overflow that got folded to zero?
https://github.com/llvm/llvm-project/pull/191278
More information about the cfe-commits
mailing list