Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

winch: Fix the type of the `table.size` output register (#13009)

Alex Crichton7a10525e09f3
diff --git a/tests/misc_testsuite/winch/table64.wast b/tests/misc_testsuite/winch/table64.wast
new file mode 100644
index 0000000000..c9108c9c97
--- /dev/null
+++ b/tests/misc_testsuite/winch/table64.wast
@@ -0,0 +1,15 @@
+;;! memory64 = true
+;;! reference_types = true
+
+(module
+ (table $t i64 10 funcref)
+ (func $leak (result i64 i64)
+ table.size $t
+ table.size $t
+ )
+ (func (export "test") (result i64)
+ call $leak
+ drop
+ )
+)
+(assert_return (invoke "test") (i64.const 10))
diff --git a/winch/codegen/src/codegen/env.rs b/winch/codegen/src/codegen/env.rs
index 51b457102e..2d88150670 100644
--- a/winch/codegen/src/codegen/env.rs
+++ b/winch/codegen/src/codegen/env.rs
@@ -41,6 +41,17 @@ pub struct TableData {
pub(crate) element_size: OperandSize,
/// The size of the current elements field.
pub(crate) current_elements_size: OperandSize,
+ /// The type of this table.
+ pub ty: Table,
+}
+
+impl TableData {
+ pub fn index_type(&self) -> WasmValType {
+ match self.ty.idx_type {
+ IndexType::I32 => WasmValType::I32,
+ IndexType::I64 => WasmValType::I64,
+ }
+ }
}
/// Heap metadata.
@@ -246,6 +257,7 @@ impl<'a, 'translation, 'data, P: PtrSize> FuncEnv<'a, 'translation, 'data, P> {
current_elements_size: OperandSize::from_bytes(
self.vmoffsets.size_of_vmtable_definition_current_elements(),
),
+ ty: self.translation.module.tables[index],
})
}
}
diff --git a/winch/codegen/src/codegen/mod.rs b/winch/codegen/src/codegen/mod.rs
index 12bed240b8..978768f67b 100644
--- a/winch/codegen/src/codegen/mod.rs
+++ b/winch/codegen/src/codegen/mod.rs
@@ -1073,7 +1073,8 @@ where
masm.load(size_addr, writable!(size), table_data.current_elements_size)
})?;
- self.context.stack.push(TypedReg::i32(size).into());
+ let dst = TypedReg::new(table_data.index_type(), size);
+ self.context.stack.push(dst.into());
Ok(())
}