Debian Codegraph @

js/src/jit-test/tests/wasm/gc/cast-optimizations.js

raw
1 // Test situations where LICM can be performed
2 {
3 const { test1, test2 } = wasmEvalText(`(module
4 (type $a1 (sub (array (mut funcref))))
5 (type $a2 (sub (array (mut i32))))
6
7 (func (export "test1") (result anyref)
8 (local anyref i32)
9 loop
10 (ref.i31 (i32.const 0))
11 ref.cast anyref
12 local.set 0
13
14 (local.set 1 (i32.add (local.get 1) (i32.const 1)))
15 (br_if 0 (i32.gt_u (local.get 1) (i32.const 10)))
16 end
17 local.get 0
18 )
19 (func (export "test2") (result anyref)
20 (local anyref i32)
21 loop
22 (ref.i31 (i32.const 0))
23 ref.cast anyref
24 ref.cast (ref null $a2)
25 local.tee 0
26
27 ref.test (ref null $a1)
28 br_if 0
29 end
30 local.get 0
31 )
32 )`).exports;
33
34 assertEq(test1(), 0);
35 assertErrorMessage(() => test2(), WebAssembly.RuntimeError, /bad cast/);
36 }