github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/integration_test/spectest/v1/testdata/elem.wast (about) 1 ;; Test the element section 2 3 ;; Syntax 4 (module 5 (table $t 10 funcref) 6 (func $f) 7 (elem (i32.const 0)) 8 (elem (i32.const 0) $f $f) 9 (elem (offset (i32.const 0))) 10 (elem (offset (i32.const 0)) $f $f) 11 (elem 0 (i32.const 0)) 12 (elem 0x0 (i32.const 0) $f $f) 13 (elem 0x000 (offset (i32.const 0))) 14 (elem 0 (offset (i32.const 0)) $f $f) 15 (elem $t (i32.const 0)) 16 (elem $t (i32.const 0) $f $f) 17 (elem $t (offset (i32.const 0))) 18 (elem $t (offset (i32.const 0)) $f $f) 19 ) 20 21 ;; Basic use 22 23 (module 24 (table 10 funcref) 25 (func $f) 26 (elem (i32.const 0) $f) 27 ) 28 (module 29 (import "spectest" "table" (table 10 funcref)) 30 (func $f) 31 (elem (i32.const 0) $f) 32 ) 33 34 (module 35 (table 10 funcref) 36 (func $f) 37 (elem (i32.const 0) $f) 38 (elem (i32.const 3) $f) 39 (elem (i32.const 7) $f) 40 (elem (i32.const 5) $f) 41 (elem (i32.const 3) $f) 42 ) 43 (module 44 (import "spectest" "table" (table 10 funcref)) 45 (func $f) 46 (elem (i32.const 9) $f) 47 (elem (i32.const 3) $f) 48 (elem (i32.const 7) $f) 49 (elem (i32.const 3) $f) 50 (elem (i32.const 5) $f) 51 ) 52 53 (module 54 (global (import "spectest" "global_i32") i32) 55 (table 1000 funcref) 56 (func $f) 57 (elem (global.get 0) $f) 58 ) 59 60 (module 61 (global $g (import "spectest" "global_i32") i32) 62 (table 1000 funcref) 63 (func $f) 64 (elem (global.get $g) $f) 65 ) 66 67 (module 68 (type $out-i32 (func (result i32))) 69 (table 10 funcref) 70 (elem (i32.const 7) $const-i32-a) 71 (elem (i32.const 9) $const-i32-b) 72 (func $const-i32-a (type $out-i32) (i32.const 65)) 73 (func $const-i32-b (type $out-i32) (i32.const 66)) 74 (func (export "call-7") (type $out-i32) 75 (call_indirect (type $out-i32) (i32.const 7)) 76 ) 77 (func (export "call-9") (type $out-i32) 78 (call_indirect (type $out-i32) (i32.const 9)) 79 ) 80 ) 81 (assert_return (invoke "call-7") (i32.const 65)) 82 (assert_return (invoke "call-9") (i32.const 66)) 83 84 ;; Corner cases 85 86 (module 87 (table 10 funcref) 88 (func $f) 89 (elem (i32.const 9) $f) 90 ) 91 (module 92 (import "spectest" "table" (table 10 funcref)) 93 (func $f) 94 (elem (i32.const 9) $f) 95 ) 96 97 (module 98 (table 0 funcref) 99 (elem (i32.const 0)) 100 ) 101 (module 102 (import "spectest" "table" (table 0 funcref)) 103 (elem (i32.const 0)) 104 ) 105 106 (module 107 (table 0 0 funcref) 108 (elem (i32.const 0)) 109 ) 110 111 (module 112 (table 20 funcref) 113 (elem (i32.const 20)) 114 ) 115 116 (module 117 (import "spectest" "table" (table 0 funcref)) 118 (func $f) 119 (elem (i32.const 0) $f) 120 ) 121 122 (module 123 (import "spectest" "table" (table 0 100 funcref)) 124 (func $f) 125 (elem (i32.const 0) $f) 126 ) 127 128 (module 129 (import "spectest" "table" (table 0 funcref)) 130 (func $f) 131 (elem (i32.const 1) $f) 132 ) 133 134 (module 135 (import "spectest" "table" (table 0 30 funcref)) 136 (func $f) 137 (elem (i32.const 1) $f) 138 ) 139 140 ;; Invalid bounds for elements 141 142 (assert_unlinkable 143 (module 144 (table 0 funcref) 145 (func $f) 146 (elem (i32.const 0) $f) 147 ) 148 "elements segment does not fit" 149 ) 150 151 (assert_unlinkable 152 (module 153 (table 0 0 funcref) 154 (func $f) 155 (elem (i32.const 0) $f) 156 ) 157 "elements segment does not fit" 158 ) 159 160 (assert_unlinkable 161 (module 162 (table 0 1 funcref) 163 (func $f) 164 (elem (i32.const 0) $f) 165 ) 166 "elements segment does not fit" 167 ) 168 169 (assert_unlinkable 170 (module 171 (table 0 funcref) 172 (elem (i32.const 1)) 173 ) 174 "elements segment does not fit" 175 ) 176 177 (assert_unlinkable 178 (module 179 (table 10 funcref) 180 (func $f) 181 (elem (i32.const 10) $f) 182 ) 183 "elements segment does not fit" 184 ) 185 (assert_unlinkable 186 (module 187 (import "spectest" "table" (table 10 funcref)) 188 (func $f) 189 (elem (i32.const 10) $f) 190 ) 191 "elements segment does not fit" 192 ) 193 194 (assert_unlinkable 195 (module 196 (table 10 20 funcref) 197 (func $f) 198 (elem (i32.const 10) $f) 199 ) 200 "elements segment does not fit" 201 ) 202 (assert_unlinkable 203 (module 204 (import "spectest" "table" (table 10 funcref)) 205 (func $f) 206 (elem (i32.const 10) $f) 207 ) 208 "elements segment does not fit" 209 ) 210 211 (assert_unlinkable 212 (module 213 (table 10 funcref) 214 (func $f) 215 (elem (i32.const -1) $f) 216 ) 217 "elements segment does not fit" 218 ) 219 (assert_unlinkable 220 (module 221 (import "spectest" "table" (table 10 funcref)) 222 (func $f) 223 (elem (i32.const -1) $f) 224 ) 225 "elements segment does not fit" 226 ) 227 228 (assert_unlinkable 229 (module 230 (table 10 funcref) 231 (func $f) 232 (elem (i32.const -10) $f) 233 ) 234 "elements segment does not fit" 235 ) 236 (assert_unlinkable 237 (module 238 (import "spectest" "table" (table 10 funcref)) 239 (func $f) 240 (elem (i32.const -10) $f) 241 ) 242 "elements segment does not fit" 243 ) 244 245 ;; Element without table 246 247 (assert_invalid 248 (module 249 (func $f) 250 (elem (i32.const 0) $f) 251 ) 252 "unknown table 0" 253 ) 254 255 ;; Invalid offsets 256 257 (assert_invalid 258 (module 259 (table 1 funcref) 260 (elem (i64.const 0)) 261 ) 262 "type mismatch" 263 ) 264 265 (assert_invalid 266 (module 267 (table 1 funcref) 268 (elem (i32.ctz (i32.const 0))) 269 ) 270 "constant expression required" 271 ) 272 273 (assert_invalid 274 (module 275 (table 1 funcref) 276 (elem (nop)) 277 ) 278 "constant expression required" 279 ) 280 281 (assert_invalid 282 (module 283 (table 1 funcref) 284 (elem (offset (nop) (i32.const 0))) 285 ) 286 "constant expression required" 287 ) 288 289 (assert_invalid 290 (module 291 (table 1 funcref) 292 (elem (offset (i32.const 0) (nop))) 293 ) 294 "constant expression required" 295 ) 296 297 ;; Use of internal globals in constant expressions is not allowed in MVP. 298 ;; (assert_invalid 299 ;; (module (memory 1) (data (global.get $g)) (global $g (mut i32) (i32.const 0))) 300 ;; "constant expression required" 301 ;; ) 302 303 ;; Two elements target the same slot 304 305 (module 306 (type $out-i32 (func (result i32))) 307 (table 10 funcref) 308 (elem (i32.const 9) $const-i32-a) 309 (elem (i32.const 9) $const-i32-b) 310 (func $const-i32-a (type $out-i32) (i32.const 65)) 311 (func $const-i32-b (type $out-i32) (i32.const 66)) 312 (func (export "call-overwritten") (type $out-i32) 313 (call_indirect (type $out-i32) (i32.const 9)) 314 ) 315 ) 316 (assert_return (invoke "call-overwritten") (i32.const 66)) 317 318 (module 319 (type $out-i32 (func (result i32))) 320 (import "spectest" "table" (table 10 funcref)) 321 (elem (i32.const 9) $const-i32-a) 322 (elem (i32.const 9) $const-i32-b) 323 (func $const-i32-a (type $out-i32) (i32.const 65)) 324 (func $const-i32-b (type $out-i32) (i32.const 66)) 325 (func (export "call-overwritten-element") (type $out-i32) 326 (call_indirect (type $out-i32) (i32.const 9)) 327 ) 328 ) 329 (assert_return (invoke "call-overwritten-element") (i32.const 66)) 330 331 ;; Element sections across multiple modules change the same table 332 333 (module $module1 334 (type $out-i32 (func (result i32))) 335 (table (export "shared-table") 10 funcref) 336 (elem (i32.const 8) $const-i32-a) 337 (elem (i32.const 9) $const-i32-b) 338 (func $const-i32-a (type $out-i32) (i32.const 65)) 339 (func $const-i32-b (type $out-i32) (i32.const 66)) 340 (func (export "call-7") (type $out-i32) 341 (call_indirect (type $out-i32) (i32.const 7)) 342 ) 343 (func (export "call-8") (type $out-i32) 344 (call_indirect (type $out-i32) (i32.const 8)) 345 ) 346 (func (export "call-9") (type $out-i32) 347 (call_indirect (type $out-i32) (i32.const 9)) 348 ) 349 ) 350 351 (register "module1" $module1) 352 353 (assert_trap (invoke $module1 "call-7") "uninitialized element 7") 354 (assert_return (invoke $module1 "call-8") (i32.const 65)) 355 (assert_return (invoke $module1 "call-9") (i32.const 66)) 356 357 (module $module2 358 (type $out-i32 (func (result i32))) 359 (import "module1" "shared-table" (table 10 funcref)) 360 (elem (i32.const 7) $const-i32-c) 361 (elem (i32.const 8) $const-i32-d) 362 (func $const-i32-c (type $out-i32) (i32.const 67)) 363 (func $const-i32-d (type $out-i32) (i32.const 68)) 364 ) 365 366 (assert_return (invoke $module1 "call-7") (i32.const 67)) 367 (assert_return (invoke $module1 "call-8") (i32.const 68)) 368 (assert_return (invoke $module1 "call-9") (i32.const 66)) 369 370 (module $module3 371 (type $out-i32 (func (result i32))) 372 (import "module1" "shared-table" (table 10 funcref)) 373 (elem (i32.const 8) $const-i32-e) 374 (elem (i32.const 9) $const-i32-f) 375 (func $const-i32-e (type $out-i32) (i32.const 69)) 376 (func $const-i32-f (type $out-i32) (i32.const 70)) 377 ) 378 379 (assert_return (invoke $module1 "call-7") (i32.const 67)) 380 (assert_return (invoke $module1 "call-8") (i32.const 69)) 381 (assert_return (invoke $module1 "call-9") (i32.const 70))