Skip to content

Commit

Permalink
[maglev][arm] Fix CheckJSTypedArrayBounds index check
Browse files Browse the repository at this point in the history
... by checking for overflow when shifting the index (actually
the carry bit since mov does not affect the overflow flag).

Fixed: chromium:1459841
Bug: v8:7700
Change-Id: Ide774107d91a0c9e2b1122ebfd00dde56dd0d3c7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4677660
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#88824}
  • Loading branch information
victorgomes authored and V8 LUCI CQ committed Jul 11, 2023
1 parent 5781df7 commit a9955bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/maglev/arm/maglev-ir-arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,13 @@ void CheckJSTypedArrayBounds::GenerateCode(MaglevAssembler* masm,
int element_size = ElementsKindSize(elements_kind_);
if (element_size > 1) {
DCHECK(element_size == 2 || element_size == 4 || element_size == 8);
__ cmp(byte_length,
Operand(index, LSL, base::bits::CountTrailingZeros(element_size)));
__ mov(index,
Operand(index, LSL, base::bits::CountTrailingZeros(element_size)),
SetCC);
// MOVS does not affect the overflow flag on Arm. Since we know {index} is
// an unsigned integer, we check the carry flag.
__ EmitEagerDeoptIf(cs, DeoptimizeReason::kOutOfBounds, this);
__ cmp(byte_length, index);
} else {
__ cmp(byte_length, index);
}
Expand Down
16 changes: 16 additions & 0 deletions test/mjsunit/maglev/regress-1459841.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --allow-natives-syntax --maglev
let a = new Float32Array(1000);
function foo(i) {
return a[i];
}

%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(0));
assertEquals(0, foo(0));

%OptimizeMaglevOnNextCall(foo);
assertEquals(undefined, foo(0x40000000)); // On 32 bits, this will overflow the array index.

0 comments on commit a9955bd

Please sign in to comment.