-
Notifications
You must be signed in to change notification settings - Fork 750
Description
Describe the bug
There appears to be a bug in iwasm when handling ref.cast on a global initialized with a struct of the same type.
The following WebAssembly module reproduces the issue:
(module
(type $0 (func (result (ref struct))))
(type $1 (struct (field (mut i32))))
(global $0 (mut (ref struct)) (struct.new_default 1))
(export "main" (func 0))
(func $0
(type 0)
(global.get 0)
(ref.cast (ref 1))
)
)
Running this module on iwasm results in the error:
Exception: cast failure
Running the same module on Wasmtime or Wasmedge executes correctly and returns a reference of the expected struct type.
The global $0 is declared as (mut (ref struct)) and initialized with struct.new_default 1, i.e., an instance of type 1.
According to the specification, casting a reference to the same type should succeed, not trap.
If global.get 0 is replaced with struct.new_default 1, the expected result is obtained. Therefore, this bug is related to the global.
Version
iwasm 2.4.4
ubuntu 20.04
To Reproduce
Steps to reproduce the behavior:
- Compile iwasm with flags like '-DWAMR_BUILD_JIT=1 -DWAMR_BUILD_TAIL_CALL=1 -DWAMR_BUILD_GC=1'
- Run iwasm with CLI options like 'iwasm -f main test1.wasm'
- See error
Expected behavior
ref.struct
Actual Result
Exception: cast failure
Desktop (please complete the following information):
- Arch x86_64
- OS ubuntu 20.04