Incorrect @wasmMemoryGrow codegen for wasm64 target
rdunnington opened this issue · 0 comments
Zig Version
0.12.0
Steps to Reproduce and Observed Behavior
With this program memtest.zig
:
const KB = 1024;
const MB = 1024 * KB;
const GB = 1024 * MB;
const PAGE_SIZE = 64 * KB;
const PAGES_PER_GB = GB / PAGE_SIZE;
export fn memtest() void {
_ = @wasmMemoryGrow(0, PAGES_PER_GB * 8);
}
Building with the command:
zig build-exe memtest.zig -target wasm64-freestanding -fno-entry --export=memtest -O ReleaseSmall
Yields the codegen (translated with wasm2wat --enable-all --no-check memtest.wasm
:
(module
(type (;0;) (func))
(func (;0;) (type 0)
i32.const 131072
memory.grow
drop)
(memory (;0;) i64 16)
(global (;0;) (mut i64) (i64.const 1048576))
(export "memory" (memory 0))
(export "memtest" (func 0)))
Running wasm2wat --enable-all memtest.wasm
(without the --no-check
) yields an error:
memtest.wasm:0000043: error: type mismatch in memory.grow, expected [i64] but got [i32]
Note that an i32
is being pushed on the stack instead of an i64, even though the memory type is declared as i64
.
Expected Behavior
An i64 is pushed to the stack instead of i32
in accordance with the memory64
spec proposal:
https://github.com/WebAssembly/memory64/blob/main/proposals/memory64/Overview.md
All memory instructions are changed to use the index type, and the offset must also be in range of the index type