Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions winch/codegen/src/codegen/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub(crate) fn ensure_index_and_offset<M: MacroAssembler>(
masm: &mut M,
index: Index,
offset: u64,
ptr_size: OperandSize,
heap_ty_size: OperandSize,
) -> ImmOffset {
match u32::try_from(offset) {
// If the immediate offset fits in a u32, then we simply return.
Expand All @@ -137,7 +137,7 @@ pub(crate) fn ensure_index_and_offset<M: MacroAssembler>(
index.as_typed_reg().into(),
index.as_typed_reg().into(),
RegImm::i64(offset as i64),
ptr_size,
heap_ty_size,
TrapCode::HeapOutOfBounds,
);

Expand Down
11 changes: 8 additions & 3 deletions winch/codegen/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ where
let memory_index = MemoryIndex::from_u32(memarg.memory);
let heap = self.env.resolve_heap(memory_index);
let index = Index::from_typed_reg(self.context.pop_to_reg(self.masm, None));
let offset = bounds::ensure_index_and_offset(self.masm, index, memarg.offset, ptr_size);
let offset =
bounds::ensure_index_and_offset(self.masm, index, memarg.offset, heap.ty.into());
let offset_with_access_size = add_offset_and_access_size(offset, access_size);

let addr = match heap.style {
Expand Down Expand Up @@ -528,7 +529,7 @@ where
index_offset_and_access_size,
index_offset_and_access_size,
RegImm::i64(offset_with_access_size as i64),
ptr_size,
heap.ty.into(),
TrapCode::HeapOutOfBounds,
);

Expand Down Expand Up @@ -627,7 +628,11 @@ where
|masm, bounds, index| {
let adjusted_bounds = bounds.as_u64() - offset_with_access_size;
let index_reg = index.as_typed_reg().reg;
masm.cmp(RegImm::i64(adjusted_bounds as i64), index_reg, ptr_size);
masm.cmp(
RegImm::i64(adjusted_bounds as i64),
index_reg,
heap.ty.into(),
);
IntCmpKind::GtU
},
);
Expand Down