Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect @wasmMemoryGrow codegen for wasm64 target #19942

Closed
rdunnington opened this issue May 11, 2024 · 0 comments · Fixed by #20012
Closed

Incorrect @wasmMemoryGrow codegen for wasm64 target #19942

rdunnington opened this issue May 11, 2024 · 0 comments · Fixed by #20012
Labels
arch-wasm 32-bit and 64-bit WebAssembly bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@rdunnington
Copy link
Sponsor Contributor

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

@rdunnington rdunnington added the bug Observed behavior contradicts documented or intended behavior label May 11, 2024
@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label May 11, 2024
@Vexu Vexu added this to the 0.13.0 milestone May 11, 2024
Vexu added a commit to Vexu/zig that referenced this issue May 20, 2024
andrewrk pushed a commit that referenced this issue May 22, 2024
@andrewrk andrewrk added the arch-wasm 32-bit and 64-bit WebAssembly label May 22, 2024
andrewrk pushed a commit that referenced this issue May 22, 2024
@andrewrk andrewrk modified the milestones: 0.14.0, 0.13.0 May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm 32-bit and 64-bit WebAssembly bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants