summaryrefslogtreecommitdiff
path: root/test/spec/table_init.wast
blob: 09cc0afdaf768115ae5fdb65a46797471783ae05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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))