Skip to content

Commit 2bf9385

Browse files
committed
Don't pad bounds check in array accumulator
1 parent d99f86d commit 2bf9385

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

crates/wasm/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1083,21 +1083,22 @@ pub fn compile<'a, O: Eq + Hash, T: Refs<'a, Opaque = O>>(f: Node<'a, O, T>) ->
10831083
// accumulator pointer for calls to the zero function for elements if this array
10841084
// stores composite values
10851085
let mut zero = Function::new([(2, ValType::I32)]);
1086-
let mut total = aligned(size * n, 8);
1086+
let bound = size * n; // use this instead of padded `total` for bounds checking
1087+
let mut total = aligned(bound, 8);
10871088
// same as zero, the local is a pointer to the end of the accumulator array, used
10881089
// for bounds checking
10891090
let mut add = Function::new([(1, ValType::I32)]);
10901091

10911092
if n > 0 {
10921093
zero.instruction(&Instruction::LocalGet(0));
1093-
zero.instruction(&Instruction::I32Const(total.try_into().unwrap()));
1094+
zero.instruction(&Instruction::I32Const(bound.try_into().unwrap()));
10941095
zero.instruction(&Instruction::I32Add);
10951096
zero.instruction(&Instruction::LocalTee(2));
10961097
zero.instruction(&Instruction::LocalSet(3));
10971098
zero.instruction(&Instruction::Loop(BlockType::Empty));
10981099

10991100
add.instruction(&Instruction::LocalGet(0));
1100-
add.instruction(&Instruction::I32Const(total.try_into().unwrap()));
1101+
add.instruction(&Instruction::I32Const(bound.try_into().unwrap()));
11011102
add.instruction(&Instruction::I32Add);
11021103
add.instruction(&Instruction::LocalSet(2));
11031104
add.instruction(&Instruction::Loop(BlockType::Empty));

0 commit comments

Comments
 (0)