Skip to content

Commit

Permalink
Add a test for non-treelike behavior of stack
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
alexcrichton committed Feb 1, 2019
1 parent 1fff613 commit 61170ba
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/core/stack.wast
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,31 @@
end
local.get $res
)

(global $temp (mut i32) (i32.const 0))
(func $add_one_to_global (result i32)
(local i32)
(global.set $temp (i32.add (i32.const 1) (global.get $temp)))
(global.get $temp)
)
(func $add_one_to_global_and_drop
(drop (call $add_one_to_global))
)
(func (export "not-quite-a-tree") (result i32)
call $add_one_to_global
call $add_one_to_global
call $add_one_to_global_and_drop
i32.add
)
)

(assert_return (invoke "fac-expr" (i64.const 25)) (i64.const 7034535277573963776))
(assert_return (invoke "fac-stack" (i64.const 25)) (i64.const 7034535277573963776))
(assert_return (invoke "fac-mixed" (i64.const 25)) (i64.const 7034535277573963776))

(assert_return (invoke "not-quite-a-tree") (i32.const 3))
(assert_return (invoke "not-quite-a-tree") (i32.const 9))


;; Syntax of flat call_indirect

Expand Down

0 comments on commit 61170ba

Please sign in to comment.