wazero
wazero copied to clipboard
Interpreter: Incorrect `i32.ne` results for value from host function (negative numbers only)
Describe the bug
Incorrect i32.ne results for value from host function (negative numbers only).
Host func result put on stack as uint64 (see internal/wasm.callGoFunc).
For -1 its 0xFFFFFFFFFFFFFFFF. But on comaration with i32(-1) from wasm its comapres with 0x00000000FFFFFFFF.
To Reproduce
Golang code:
package main
import (
"context"
"encoding/base64"
"log"
"github.com/tetratelabs/wazero"
)
func main() {
wasm, _ := base64.StdEncoding.DecodeString("AGFzbQEAAAABCgJgAX8Bf2AAAX8CDAEDZW52BGVjaG8AAAMCAQEHBwEDcnVuAAEKCwEJAEF/EABBf0cLABoEbmFtZQEMAgAEZWNobwEDcnVuAgUCAAABAA==")
config := wazero.NewRuntimeConfigInterpreter()
ctx := context.Background()
r := wazero.NewRuntimeWithConfig(ctx, config)
_, _ = r.NewHostModuleBuilder("env").
NewFunctionBuilder().
WithFunc(func(v int32) int32 {
return v
}).Export("echo").
Instantiate(ctx)
mod, _ := r.Instantiate(ctx, wasm)
run := mod.ExportedFunction("run")
result, err := run.Call(ctx)
if err != nil {
log.Fatalf("failed to call run: %v", err)
}
if result[0] == 0 {
println("OK: -1 != -1 is false")
} else {
panic("FAIL, -1 != -1 is true")
}
}
Wat code for WASM
(module
(import "env" "echo" (func $echo (param i32) (result i32)))
(func $run (result i32)
i32.const -1
call $echo
i32.const -1
i32.ne
)
(export "run" (func $run))
)
Expected behavior After run, the message "OK: -1 != -1 is false" should be displayed, but an error occurs.
Screenshots
Screenshot from debugger
Environment (please complete the relevant information):
- Go version: go1.23.5 linux/amd6
- wazero Version: v1.8.2
- Host architecture: amd64
- Runtime mode: interpreter
Additional context In compiler mode its work fine.