Skip to content

Commit 7a10525

Browse files
authored
winch: Fix the type of the table.size output register (#13009)
This commit corrects the tagged size of the output of the `table.size` instruction. Previously this was hardcoded as a 32-bit integer instead of consulting the table's index type to use the index-type-sized-register instead.
1 parent b8d5dc7 commit 7a10525

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
;;! memory64 = true
2+
;;! reference_types = true
3+
4+
(module
5+
(table $t i64 10 funcref)
6+
(func $leak (result i64 i64)
7+
table.size $t
8+
table.size $t
9+
)
10+
(func (export "test") (result i64)
11+
call $leak
12+
drop
13+
)
14+
)
15+
(assert_return (invoke "test") (i64.const 10))

winch/codegen/src/codegen/env.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ pub struct TableData {
4141
pub(crate) element_size: OperandSize,
4242
/// The size of the current elements field.
4343
pub(crate) current_elements_size: OperandSize,
44+
/// The type of this table.
45+
pub ty: Table,
46+
}
47+
48+
impl TableData {
49+
pub fn index_type(&self) -> WasmValType {
50+
match self.ty.idx_type {
51+
IndexType::I32 => WasmValType::I32,
52+
IndexType::I64 => WasmValType::I64,
53+
}
54+
}
4455
}
4556

4657
/// Heap metadata.
@@ -246,6 +257,7 @@ impl<'a, 'translation, 'data, P: PtrSize> FuncEnv<'a, 'translation, 'data, P> {
246257
current_elements_size: OperandSize::from_bytes(
247258
self.vmoffsets.size_of_vmtable_definition_current_elements(),
248259
),
260+
ty: self.translation.module.tables[index],
249261
})
250262
}
251263
}

winch/codegen/src/codegen/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,8 @@ where
10731073
masm.load(size_addr, writable!(size), table_data.current_elements_size)
10741074
})?;
10751075

1076-
self.context.stack.push(TypedReg::i32(size).into());
1076+
let dst = TypedReg::new(table_data.index_type(), size);
1077+
self.context.stack.push(dst.into());
10771078
Ok(())
10781079
}
10791080

0 commit comments

Comments
 (0)