1;;! bulk_memory = true
2
3(module $m
4  (table (export "table") funcref (elem $zero $zero $zero $zero $zero $zero $zero $zero $zero $zero))
5
6  (func $zero (result i32)
7    (i32.const 0))
8
9  (func (export "indirect-call") (param i32) (result i32)
10    local.get 0
11    call_indirect (result i32)))
12
13(register "m" $m)
14
15(assert_trap
16  (module
17    (table (import "m" "table") 10 funcref)
18
19    (func $one (result i32)
20      (i32.const 1))
21
22    ;; An in-bounds segment that should get initialized in the table.
23    (elem (i32.const 7) $one)
24
25    ;; Part of this segment is out of bounds, so none of its elements should be
26    ;; initialized into the table, and it should trap.
27    (elem (i32.const 9) $one $one $one)
28  )
29  "out of bounds"
30)
31
32;; The first `$one` segment *was* initialized OK.
33(assert_return (invoke "indirect-call" (i32.const 7)) (i32.const 1))
34
35;; The second `$one` segment is partially out of bounds, and therefore none of
36;; its elements were written into the table.
37(assert_return (invoke "indirect-call" (i32.const 9)) (i32.const 0))
38