Skip to content

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

winch: Fix `memory.size` on maximally-sized 32-bit memories (#12908)

Alex Crichtonfe5ea3974ab3
diff --git a/tests/disas/winch/x64/load/grow_load.wat b/tests/disas/winch/x64/load/grow_load.wat
index 5c88ae5e85..b791c35ef2 100644
--- a/tests/disas/winch/x64/load/grow_load.wat
+++ b/tests/disas/winch/x64/load/grow_load.wat
@@ -34,7 +34,7 @@
;; movq 0x18(%r11), %r11
;; addq $0x70, %r11
;; cmpq %rsp, %r11
-;; ja 0x134
+;; ja 0x135
;; 1c: movq %rsi, %r14
;; subq $0x60, %rsp
;; movq %rsi, 0x58(%rsp)
@@ -58,7 +58,7 @@
;; subl $1, %eax
;; movl %eax, 0x60(%r14)
;; movq 0x40(%r14), %rax
-;; shrl $0x10, %eax
+;; shrq $0x10, %rax
;; subq $4, %rsp
;; movl %eax, (%rsp)
;; subq $0xc, %rsp
@@ -74,11 +74,11 @@
;; addq %rax, %rcx
;; addq $0x23024, %rcx
;; movsbq (%rcx), %rax
-;; movss 0x5d(%rip), %xmm0
+;; movss 0x5c(%rip), %xmm0
;; subq $0xc, %rsp
-;; movsd 0x55(%rip), %xmm15
+;; movsd 0x54(%rip), %xmm15
;; movsd %xmm15, (%rsp)
-;; movss 0x3e(%rip), %xmm15
+;; movss 0x3d(%rip), %xmm15
;; movss %xmm15, 8(%rsp)
;; movq 0x14(%rsp), %rax
;; movsd (%rsp), %xmm15
@@ -90,13 +90,12 @@
;; addq $0x60, %rsp
;; popq %rbp
;; retq
-;; 134: ud2
-;; 136: addb %al, (%rax)
-;; 138: addb %al, (%rax)
-;; 13a: addb %al, (%rax)
-;; 13c: addb %al, (%rax)
-;; 13e: addb %al, (%rax)
-;; 140: addb %al, (%rax)
-;; 142: addb %al, (%rax)
-;; 144: addb %al, (%rax)
-;; 146: addb %al, (%rax)
+;; 135: ud2
+;; 137: addb %al, (%rax)
+;; 139: addb %al, (%rax)
+;; 13b: addb %al, (%rax)
+;; 13d: addb %al, (%rax)
+;; 13f: addb %al, (%rax)
+;; 141: addb %al, (%rax)
+;; 143: addb %al, (%rax)
+;; 145: addb %al, (%rax)
diff --git a/tests/misc_testsuite/big-memory-behavior.wast b/tests/misc_testsuite/big-memory-behavior.wast
index 0c7d9e08cf..d336193451 100644
--- a/tests/misc_testsuite/big-memory-behavior.wast
+++ b/tests/misc_testsuite/big-memory-behavior.wast
@@ -1,14 +1,19 @@
;;! hogs_memory = true
(module
- (memory 0xffff)
+ (memory 0xffff)
(func (export "grow") (param i32) (result i32)
local.get 0
memory.grow)
+
+ (func (export "size") (result i32)
+ memory.size)
)
(assert_return (invoke "grow" (i32.const 0)) (i32.const 0xffff))
+(assert_return (invoke "size") (i32.const 0xffff))
(assert_return (invoke "grow" (i32.const 1)) (i32.const 0xffff))
+(assert_return (invoke "size") (i32.const 0x10000))
(assert_return (invoke "grow" (i32.const 0)) (i32.const 0x10000))
(assert_return (invoke "grow" (i32.const 1)) (i32.const -1))
diff --git a/winch/codegen/src/codegen/mod.rs b/winch/codegen/src/codegen/mod.rs
index 748078c554..7d77111f52 100644
--- a/winch/codegen/src/codegen/mod.rs
+++ b/winch/codegen/src/codegen/mod.rs
@@ -1100,7 +1100,7 @@ where
Imm::i32(pow as i32),
dst.into(),
ShiftKind::ShrU,
- heap_data.index_type().try_into()?,
+ self.env.ptr_type().try_into()?,
)?;
self.context.stack.push(dst.into());
Ok(())