diff options
author | Alon Zakai <azakai@google.com> | 2024-08-16 12:53:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-16 12:53:52 -0700 |
commit | 958ff4115e542ef1d0ae712f4961e342386efe54 (patch) | |
tree | 7805d641d9a73b32650a053931c4bd8c3814d804 /test/spec | |
parent | 7209629bec3961fcc12b150ba6df546d3997b6c2 (diff) | |
download | binaryen-958ff4115e542ef1d0ae712f4961e342386efe54.tar.gz binaryen-958ff4115e542ef1d0ae712f4961e342386efe54.tar.bz2 binaryen-958ff4115e542ef1d0ae712f4961e342386efe54.zip |
Implement table.init (#6827)
Also use TableInit in the interpreter to initialize module's table
state, which will now handle traps properly, fixing #6431
Diffstat (limited to 'test/spec')
-rw-r--r-- | test/spec/table_init.wast | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/spec/table_init.wast b/test/spec/table_init.wast new file mode 100644 index 000000000..09cc0afda --- /dev/null +++ b/test/spec/table_init.wast @@ -0,0 +1,52 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --output=fuzz-exec and should not be edited. + +;; RUN: wasm-opt %s -all --fuzz-exec-before -q -o /dev/null 2>&1 | filecheck %s + +;; The elem is out of bounds, leading to a trap during initialization. +(assert_unlinkable + (module + (table $table 1 1 funcref) + (elem $elem (i32.const 1) $foo) + (func $foo) + ) + "trap" +) + +;; Now it is in bounds, with the elem offset reduced to 0. +(module + (table $table 1 1 funcref) + (elem $elem (i32.const 0) $foo) + (func $foo) +) + +;; The table begins with a function that returns zero. table.init will replace +;; it with one that returns 1. +(module + (type $i (func (result i32))) + + (table $table 10 funcref) + (elem $zero (i32.const 0) $zero) + (elem $one $one) + + (func $call (export "call") (result i32) + (call_indirect (type $i) (i32.const 0)) + ) + + (func $init (export "init") (result i32) + (table.init $table $one (i32.const 0) (i32.const 0) (i32.const 1)) + (call $call) + ) + + (func $zero (result i32) + (i32.const 0) + ) + + (func $one (result i32) + (i32.const 1) + ) +) + +;; First we get 0, then 1. +(assert_return (invoke "call") (i32.const 0)) +(assert_return (invoke "init") (i32.const 1)) + |