llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[DoNotMerge][CodeGen] Fix missing bounds check on ++/-- of array subscripts

Open rapidsna opened this issue 4 months ago • 0 comments

The four inc/dec visitors in ScalarExprEmitter emitted the subexpression's lvalue via EmitLValue, bypassing EmitCheckedLValue. For an ArraySubscriptExpr, that emits the ASE with Accessed=false, which produces two different bugs:

  • -fsanitize=array-bounds: the compare degrades from index < N to index <= N (EmitBoundsCheckImpl picks ICmpULT/ICmpULE on Accessed), so the write at index == N slips through.

  • -fbounds-safety: the firebloom bounds-check emission in EmitWidePtrArraySubscriptExpr is fully gated on Accessed, so no check is emitted at all for ++/--.

Route inc/dec through EmitCheckedLValue(..., TCK_Store), matching what plain and compound assignment already do. TCK_Store is correct because inc/dec is a read-modify-write whose store side is the one that needs the bounds guarantee.

Co-Authored-By: Claude Opus 4.7 [email protected]

rdar://174356716

rapidsna avatar Jul 29 '26 17:07 rapidsna