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 b4e8343
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/core/call.wast
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,22 @@
(func (export "as-convert-operand") (result i64)
(block (result i64) (i64.extend_i32_s (call $dummy (i32.const 1))))
)

(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 "type-i32") (i32.const 0x132))
Expand Down Expand Up @@ -308,6 +324,9 @@
(assert_return (invoke "as-compare-right") (i32.const 1))
(assert_return (invoke "as-convert-operand") (i64.const 1))

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

;; Invalid typing

(assert_invalid
Expand Down

0 comments on commit b4e8343

Please sign in to comment.