================
@@ -1323,14 +1321,23 @@ void CodeGenFunction::EmitBoundsCheckImpl(const Expr 
*ArrayExpr,
   llvm::Value *IndexInst = Builder.CreateIntCast(IndexVal, Ty, IndexSigned);
   llvm::Value *BoundsInst = Builder.CreateIntCast(BoundsVal, Ty, false);
 
+  // For a '__sized_by' bound the loaded value is a byte count, so compare it
+  // against the index scaled to bytes: 'index * sizeof(element)'. The
+  // element-counting ('__counted_by') and plain-array cases pass a scale of 1.
+  // The value reported to the runtime handler stays the (unscaled) index.
+  llvm::Value *CheckIndex = IndexInst;
+  if (IndexScale > CharUnits::One())
+    CheckIndex = Builder.CreateMul(
----------------
usama54321 wrote:

This could overflow

https://github.com/llvm/llvm-project/pull/213795
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to