Skip to content

Commit 7475815

Browse files
alexcrichtongumb0
authored andcommitted
Add a test for non-treelike behavior of stack (WebAssembly#961)
We've recently found a bug in a WebAssembly library we've been working with where we're mapping WebAssembly to a tree-like IR internally. The way we parse into this representation, however, has a bug when the function isn't itself tree-like but rather exibits properties that exploit a stack machine. For example this isn't so straightforward to represent in a tree-like fashion: (import "" "a" (func $foo)) (import "" "b" (func $foo (result i32))) (func (result i32) call $b call $b call $a i32.xor) The extra `call $a` in the middle is valid `WebAssembly` but needs special treatment when converting to a more tree-like IR format. I figured it'd be good to ensure there's a spec test covering this case as we currently pass the suite of spec tests but still contain this bug!
1 parent 6fc0b31 commit 7475815

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/core/stack.wast

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,31 @@
125125
end
126126
local.get $res
127127
)
128+
129+
(global $temp (mut i32) (i32.const 0))
130+
(func $add_one_to_global (result i32)
131+
(local i32)
132+
(global.set $temp (i32.add (i32.const 1) (global.get $temp)))
133+
(global.get $temp)
134+
)
135+
(func $add_one_to_global_and_drop
136+
(drop (call $add_one_to_global))
137+
)
138+
(func (export "not-quite-a-tree") (result i32)
139+
call $add_one_to_global
140+
call $add_one_to_global
141+
call $add_one_to_global_and_drop
142+
i32.add
143+
)
128144
)
129145

130146
(assert_return (invoke "fac-expr" (i64.const 25)) (i64.const 7034535277573963776))
131147
(assert_return (invoke "fac-stack" (i64.const 25)) (i64.const 7034535277573963776))
132148
(assert_return (invoke "fac-mixed" (i64.const 25)) (i64.const 7034535277573963776))
133149

150+
(assert_return (invoke "not-quite-a-tree") (i32.const 3))
151+
(assert_return (invoke "not-quite-a-tree") (i32.const 9))
152+
134153

135154
;; Syntax of flat call_indirect
136155

0 commit comments

Comments
 (0)