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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
;; Test the element section
;; Syntax
(module
(table $t 10 funcref)
(func $f)
(func $g)
;; Passive
(elem funcref)
(elem funcref (ref.func $f) (item ref.func $f) (item (ref.null func)) (ref.func $g))
(elem func)
(elem func $f $f $g $g)
(elem $p1 funcref)
(elem $p2 funcref (ref.func $f) (ref.func $f) (ref.null func) (ref.func $g))
(elem $p3 func)
(elem $p4 func $f $f $g $g)
;; Active
(elem (table $t) (i32.const 0) funcref)
(elem (table $t) (i32.const 0) funcref (ref.func $f) (ref.null func))
(elem (table $t) (i32.const 0) func)
(elem (table $t) (i32.const 0) func $f $g)
(elem (table $t) (offset (i32.const 0)) funcref)
(elem (table $t) (offset (i32.const 0)) func $f $g)
(elem (table 0) (i32.const 0) func)
;; (elem (table 0x0) (i32.const 0) func $f $f)
;; (elem (table 0x000) (offset (i32.const 0)) func)
(elem (table 0) (offset (i32.const 0)) func $f $f)
(elem (table $t) (i32.const 0) func)
(elem (table $t) (i32.const 0) func $f $f)
(elem (table $t) (offset (i32.const 0)) func)
(elem (table $t) (offset (i32.const 0)) func $f $f)
(elem (offset (i32.const 0)))
(elem (offset (i32.const 0)) funcref (ref.func $f) (ref.null func))
(elem (offset (i32.const 0)) func $f $f)
(elem (offset (i32.const 0)) $f $f)
(elem (i32.const 0))
(elem (i32.const 0) funcref (ref.func $f) (ref.null func))
(elem (i32.const 0) func $f $f)
(elem (i32.const 0) $f $f)
(elem $a1 (table $t) (i32.const 0) funcref)
(elem $a2 (table $t) (i32.const 0) funcref (ref.func $f) (ref.null func))
(elem $a3 (table $t) (i32.const 0) func)
(elem $a4 (table $t) (i32.const 0) func $f $g)
(elem $a9 (table $t) (offset (i32.const 0)) funcref)
(elem $a10 (table $t) (offset (i32.const 0)) func $f $g)
(elem $a11 (table 0) (i32.const 0) func)
;; (elem $a12 (table 0x0) (i32.const 0) func $f $f)
;; (elem $a13 (table 0x000) (offset (i32.const 0)) func)
(elem $a14 (table 0) (offset (i32.const 0)) func $f $f)
(elem $a15 (table $t) (i32.const 0) func)
(elem $a16 (table $t) (i32.const 0) func $f $f)
(elem $a17 (table $t) (offset (i32.const 0)) func)
(elem $a18 (table $t) (offset (i32.const 0)) func $f $f)
(elem $a19 (offset (i32.const 0)))
(elem $a20 (offset (i32.const 0)) funcref (ref.func $f) (ref.null func))
(elem $a21 (offset (i32.const 0)) func $f $f)
(elem $a22 (offset (i32.const 0)) $f $f)
(elem $a23 (i32.const 0))
(elem $a24 (i32.const 0) funcref (ref.func $f) (ref.null func))
(elem $a25 (i32.const 0) func $f $f)
(elem $a26 (i32.const 0) $f $f)
;; Declarative
(elem declare funcref)
(elem declare funcref (ref.func $f) (ref.func $f) (ref.null func) (ref.func $g))
(elem declare func)
(elem declare func $f $f $g $g)
(elem $d1 declare funcref)
(elem $d2 declare funcref (ref.func $f) (ref.func $f) (ref.null func) (ref.func $g))
(elem $d3 declare func)
(elem $d4 declare func $f $f $g $g)
)
(module
(func $f)
(func $g)
(table $t1 funcref (elem (ref.func $f) (ref.null func) (ref.func $g)))
(table $t2 (ref null func) (elem (ref.func $f) (ref.null func) (ref.func $g)))
)
;; Basic use
(module
(table 10 funcref)
(func $f)
(elem (i32.const 0) $f)
)
(module
(import "spectest" "table" (table 10 funcref))
(func $f)
(elem (i32.const 0) $f)
)
(module
(table 10 funcref)
(func $f)
(elem (i32.const 0) $f)
(elem (i32.const 3) $f)
(elem (i32.const 7) $f)
(elem (i32.const 5) $f)
(elem (i32.const 3) $f)
)
(module
(import "spectest" "table" (table 10 funcref))
(func $f)
(elem (i32.const 9) $f)
(elem (i32.const 3) $f)
(elem (i32.const 7) $f)
(elem (i32.const 3) $f)
(elem (i32.const 5) $f)
)
(module
(global (import "spectest" "global_i32") i32)
(table 1000 funcref)
(func $f)
(elem (global.get 0) $f)
)
(module
(global $g (import "spectest" "global_i32") i32)
(table 1000 funcref)
(func $f)
(elem (global.get $g) $f)
)
(module
(type $out-i32 (func (result i32)))
(table 10 funcref)
(elem (i32.const 7) $const-i32-a)
(elem (i32.const 9) $const-i32-b)
(func $const-i32-a (type $out-i32) (i32.const 65))
(func $const-i32-b (type $out-i32) (i32.const 66))
(func (export "call-7") (type $out-i32)
(call_indirect (type $out-i32) (i32.const 7))
)
(func (export "call-9") (type $out-i32)
(call_indirect (type $out-i32) (i32.const 9))
)
)
(assert_return (invoke "call-7") (i32.const 65))
(assert_return (invoke "call-9") (i32.const 66))
;; Corner cases
(module
(table 10 funcref)
(func $f)
(elem (i32.const 9) $f)
)
(module
(import "spectest" "table" (table 10 funcref))
(func $f)
(elem (i32.const 9) $f)
)
(module
(table 0 funcref)
(elem (i32.const 0))
)
(module
(import "spectest" "table" (table 0 funcref))
(elem (i32.const 0))
)
(module
(table 0 0 funcref)
(elem (i32.const 0))
)
(module
(table 20 funcref)
(elem (i32.const 20))
)
;;; We cannot enable these yet since we check table bounds at validation stage,
;;; which is incorrect for imported tables.
;; (module
;; (import "spectest" "table" (table 0 funcref))
;; (func $f)
;; (elem (i32.const 0) $f)
;; )
;; (module
;; (import "spectest" "table" (table 0 100 funcref))
;; (func $f)
;; (elem (i32.const 0) $f)
;; )
;; (module
;; (import "spectest" "table" (table 0 funcref))
;; (func $f)
;; (elem (i32.const 1) $f)
;; )
;; (module
;; (import "spectest" "table" (table 0 30 funcref))
;; (func $f)
;; (elem (i32.const 1) $f)
;; )
;; Two elements target the same slot
(module
(type $out-i32 (func (result i32)))
(table 10 funcref)
(elem (i32.const 9) $const-i32-a)
(elem (i32.const 9) $const-i32-b)
(func $const-i32-a (type $out-i32) (i32.const 65))
(func $const-i32-b (type $out-i32) (i32.const 66))
(func (export "call-overwritten") (type $out-i32)
(call_indirect (type $out-i32) (i32.const 9))
)
)
(assert_return (invoke "call-overwritten") (i32.const 66))
(module
(type $out-i32 (func (result i32)))
(import "spectest" "table" (table 10 funcref))
(elem (i32.const 9) $const-i32-a)
(elem (i32.const 9) $const-i32-b)
(func $const-i32-a (type $out-i32) (i32.const 65))
(func $const-i32-b (type $out-i32) (i32.const 66))
(func (export "call-overwritten-element") (type $out-i32)
(call_indirect (type $out-i32) (i32.const 9))
)
)
(assert_return (invoke "call-overwritten-element") (i32.const 66))
;; Element sections across multiple modules change the same table
(module $module1
(type $out-i32 (func (result i32)))
(table (export "shared-table") 10 funcref)
(elem (i32.const 8) $const-i32-a)
(elem (i32.const 9) $const-i32-b)
(func $const-i32-a (type $out-i32) (i32.const 65))
(func $const-i32-b (type $out-i32) (i32.const 66))
(func (export "call-7") (type $out-i32)
(call_indirect (type $out-i32) (i32.const 7))
)
(func (export "call-8") (type $out-i32)
(call_indirect (type $out-i32) (i32.const 8))
)
(func (export "call-9") (type $out-i32)
(call_indirect (type $out-i32) (i32.const 9))
)
)
(assert_invalid
(module
(type $none_=>_none (func))
(table 0 (ref null $none_=>_none))
(elem (i32.const 0) funcref)
)
"invalid"
)
|