File: partial-init-table-segment.wast

package info (click to toggle)
rust-wasmtime 26.0.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 48,492 kB
  • sloc: ansic: 4,003; sh: 561; javascript: 542; cpp: 254; asm: 175; ml: 96; makefile: 55
file content (35 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download | duplicates (3)
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
(module $m
  (table (export "table") funcref (elem $zero $zero $zero $zero $zero $zero $zero $zero $zero $zero))

  (func $zero (result i32)
    (i32.const 0))

  (func (export "indirect-call") (param i32) (result i32)
    local.get 0
    call_indirect (result i32)))

(register "m" $m)

(assert_trap
  (module
    (table (import "m" "table") 10 funcref)

    (func $one (result i32)
      (i32.const 1))

    ;; An in-bounds segment that should get initialized in the table.
    (elem (i32.const 7) $one)

    ;; Part of this segment is out of bounds, so none of its elements should be
    ;; initialized into the table, and it should trap.
    (elem (i32.const 9) $one $one $one)
  )
  "out of bounds"
)

;; The first `$one` segment *was* initialized OK.
(assert_return (invoke "indirect-call" (i32.const 7)) (i32.const 1))

;; The second `$one` segment is partially out of bounds, and therefore none of
;; its elements were written into the table.
(assert_return (invoke "indirect-call" (i32.const 9)) (i32.const 0))