github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/integration_test/spectest/v2/testdata/br.wast (about) 1 ;; Test `br` operator 2 3 (module 4 ;; Auxiliary definition 5 (func $dummy) 6 7 (func (export "type-i32") (block (drop (i32.ctz (br 0))))) 8 (func (export "type-i64") (block (drop (i64.ctz (br 0))))) 9 (func (export "type-f32") (block (drop (f32.neg (br 0))))) 10 (func (export "type-f64") (block (drop (f64.neg (br 0))))) 11 (func (export "type-i32-i32") (block (drop (i32.add (br 0))))) 12 (func (export "type-i64-i64") (block (drop (i64.add (br 0))))) 13 (func (export "type-f32-f32") (block (drop (f32.add (br 0))))) 14 (func (export "type-f64-f64") (block (drop (f64.add (br 0))))) 15 16 (func (export "type-i32-value") (result i32) 17 (block (result i32) (i32.ctz (br 0 (i32.const 1)))) 18 ) 19 (func (export "type-i64-value") (result i64) 20 (block (result i64) (i64.ctz (br 0 (i64.const 2)))) 21 ) 22 (func (export "type-f32-value") (result f32) 23 (block (result f32) (f32.neg (br 0 (f32.const 3)))) 24 ) 25 (func (export "type-f64-value") (result f64) 26 (block (result f64) (f64.neg (br 0 (f64.const 4)))) 27 ) 28 (func (export "type-f64-f64-value") (result f64 f64) 29 (block (result f64 f64) 30 (f64.add (br 0 (f64.const 4) (f64.const 5))) (f64.const 6) 31 ) 32 ) 33 34 (func (export "as-block-first") 35 (block (br 0) (call $dummy)) 36 ) 37 (func (export "as-block-mid") 38 (block (call $dummy) (br 0) (call $dummy)) 39 ) 40 (func (export "as-block-last") 41 (block (nop) (call $dummy) (br 0)) 42 ) 43 (func (export "as-block-value") (result i32) 44 (block (result i32) (nop) (call $dummy) (br 0 (i32.const 2))) 45 ) 46 47 (func (export "as-loop-first") (result i32) 48 (block (result i32) (loop (result i32) (br 1 (i32.const 3)) (i32.const 2))) 49 ) 50 (func (export "as-loop-mid") (result i32) 51 (block (result i32) 52 (loop (result i32) (call $dummy) (br 1 (i32.const 4)) (i32.const 2)) 53 ) 54 ) 55 (func (export "as-loop-last") (result i32) 56 (block (result i32) 57 (loop (result i32) (nop) (call $dummy) (br 1 (i32.const 5))) 58 ) 59 ) 60 61 (func (export "as-br-value") (result i32) 62 (block (result i32) (br 0 (br 0 (i32.const 9)))) 63 ) 64 65 (func (export "as-br_if-cond") 66 (block (br_if 0 (br 0))) 67 ) 68 (func (export "as-br_if-value") (result i32) 69 (block (result i32) 70 (drop (br_if 0 (br 0 (i32.const 8)) (i32.const 1))) (i32.const 7) 71 ) 72 ) 73 (func (export "as-br_if-value-cond") (result i32) 74 (block (result i32) 75 (drop (br_if 0 (i32.const 6) (br 0 (i32.const 9)))) (i32.const 7) 76 ) 77 ) 78 79 (func (export "as-br_table-index") 80 (block (br_table 0 0 0 (br 0))) 81 ) 82 (func (export "as-br_table-value") (result i32) 83 (block (result i32) 84 (br_table 0 0 0 (br 0 (i32.const 10)) (i32.const 1)) (i32.const 7) 85 ) 86 ) 87 (func (export "as-br_table-value-index") (result i32) 88 (block (result i32) 89 (br_table 0 0 (i32.const 6) (br 0 (i32.const 11))) (i32.const 7) 90 ) 91 ) 92 93 (func (export "as-return-value") (result i64) 94 (block (result i64) (return (br 0 (i64.const 7)))) 95 ) 96 (func (export "as-return-values") (result i32 i64) 97 (i32.const 2) 98 (block (result i64) (return (br 0 (i32.const 1) (i64.const 7)))) 99 ) 100 101 (func (export "as-if-cond") (result i32) 102 (block (result i32) 103 (if (result i32) (br 0 (i32.const 2)) 104 (then (i32.const 0)) 105 (else (i32.const 1)) 106 ) 107 ) 108 ) 109 (func (export "as-if-then") (param i32 i32) (result i32) 110 (block (result i32) 111 (if (result i32) (local.get 0) 112 (then (br 1 (i32.const 3))) 113 (else (local.get 1)) 114 ) 115 ) 116 ) 117 (func (export "as-if-else") (param i32 i32) (result i32) 118 (block (result i32) 119 (if (result i32) (local.get 0) 120 (then (local.get 1)) 121 (else (br 1 (i32.const 4))) 122 ) 123 ) 124 ) 125 126 (func (export "as-select-first") (param i32 i32) (result i32) 127 (block (result i32) 128 (select (br 0 (i32.const 5)) (local.get 0) (local.get 1)) 129 ) 130 ) 131 (func (export "as-select-second") (param i32 i32) (result i32) 132 (block (result i32) 133 (select (local.get 0) (br 0 (i32.const 6)) (local.get 1)) 134 ) 135 ) 136 (func (export "as-select-cond") (result i32) 137 (block (result i32) 138 (select (i32.const 0) (i32.const 1) (br 0 (i32.const 7))) 139 ) 140 ) 141 (func (export "as-select-all") (result i32) 142 (block (result i32) (select (br 0 (i32.const 8)))) 143 ) 144 145 (func $f (param i32 i32 i32) (result i32) (i32.const -1)) 146 (func (export "as-call-first") (result i32) 147 (block (result i32) 148 (call $f (br 0 (i32.const 12)) (i32.const 2) (i32.const 3)) 149 ) 150 ) 151 (func (export "as-call-mid") (result i32) 152 (block (result i32) 153 (call $f (i32.const 1) (br 0 (i32.const 13)) (i32.const 3)) 154 ) 155 ) 156 (func (export "as-call-last") (result i32) 157 (block (result i32) 158 (call $f (i32.const 1) (i32.const 2) (br 0 (i32.const 14))) 159 ) 160 ) 161 (func (export "as-call-all") (result i32) 162 (block (result i32) (call $f (br 0 (i32.const 15)))) 163 ) 164 165 (type $sig (func (param i32 i32 i32) (result i32))) 166 (table funcref (elem $f)) 167 (func (export "as-call_indirect-func") (result i32) 168 (block (result i32) 169 (call_indirect (type $sig) 170 (br 0 (i32.const 20)) 171 (i32.const 1) (i32.const 2) (i32.const 3) 172 ) 173 ) 174 ) 175 (func (export "as-call_indirect-first") (result i32) 176 (block (result i32) 177 (call_indirect (type $sig) 178 (i32.const 0) 179 (br 0 (i32.const 21)) (i32.const 2) (i32.const 3) 180 ) 181 ) 182 ) 183 (func (export "as-call_indirect-mid") (result i32) 184 (block (result i32) 185 (call_indirect (type $sig) 186 (i32.const 0) 187 (i32.const 1) (br 0 (i32.const 22)) (i32.const 3) 188 ) 189 ) 190 ) 191 (func (export "as-call_indirect-last") (result i32) 192 (block (result i32) 193 (call_indirect (type $sig) 194 (i32.const 0) 195 (i32.const 1) (i32.const 2) (br 0 (i32.const 23)) 196 ) 197 ) 198 ) 199 (func (export "as-call_indirect-all") (result i32) 200 (block (result i32) (call_indirect (type $sig) (br 0 (i32.const 24)))) 201 ) 202 203 (func (export "as-local.set-value") (result i32) (local f32) 204 (block (result i32) (local.set 0 (br 0 (i32.const 17))) (i32.const -1)) 205 ) 206 (func (export "as-local.tee-value") (result i32) (local i32) 207 (block (result i32) (local.tee 0 (br 0 (i32.const 1)))) 208 ) 209 (global $a (mut i32) (i32.const 10)) 210 (func (export "as-global.set-value") (result i32) 211 (block (result i32) (global.set $a (br 0 (i32.const 1)))) 212 ) 213 214 (memory 1) 215 (func (export "as-load-address") (result f32) 216 (block (result f32) (f32.load (br 0 (f32.const 1.7)))) 217 ) 218 (func (export "as-loadN-address") (result i64) 219 (block (result i64) (i64.load8_s (br 0 (i64.const 30)))) 220 ) 221 222 (func (export "as-store-address") (result i32) 223 (block (result i32) 224 (f64.store (br 0 (i32.const 30)) (f64.const 7)) (i32.const -1) 225 ) 226 ) 227 (func (export "as-store-value") (result i32) 228 (block (result i32) 229 (i64.store (i32.const 2) (br 0 (i32.const 31))) (i32.const -1) 230 ) 231 ) 232 (func (export "as-store-both") (result i32) 233 (block (result i32) 234 (i64.store (br 0 (i32.const 32))) (i32.const -1) 235 ) 236 ) 237 238 (func (export "as-storeN-address") (result i32) 239 (block (result i32) 240 (i32.store8 (br 0 (i32.const 32)) (i32.const 7)) (i32.const -1) 241 ) 242 ) 243 (func (export "as-storeN-value") (result i32) 244 (block (result i32) 245 (i64.store16 (i32.const 2) (br 0 (i32.const 33))) (i32.const -1) 246 ) 247 ) 248 (func (export "as-storeN-both") (result i32) 249 (block (result i32) 250 (i64.store16 (br 0 (i32.const 34))) (i32.const -1) 251 ) 252 ) 253 254 (func (export "as-unary-operand") (result f32) 255 (block (result f32) (f32.neg (br 0 (f32.const 3.4)))) 256 ) 257 258 (func (export "as-binary-left") (result i32) 259 (block (result i32) (i32.add (br 0 (i32.const 3)) (i32.const 10))) 260 ) 261 (func (export "as-binary-right") (result i64) 262 (block (result i64) (i64.sub (i64.const 10) (br 0 (i64.const 45)))) 263 ) 264 (func (export "as-binary-both") (result i32) 265 (block (result i32) (i32.add (br 0 (i32.const 46)))) 266 ) 267 268 (func (export "as-test-operand") (result i32) 269 (block (result i32) (i32.eqz (br 0 (i32.const 44)))) 270 ) 271 272 (func (export "as-compare-left") (result i32) 273 (block (result i32) (f64.le (br 0 (i32.const 43)) (f64.const 10))) 274 ) 275 (func (export "as-compare-right") (result i32) 276 (block (result i32) (f32.ne (f32.const 10) (br 0 (i32.const 42)))) 277 ) 278 (func (export "as-compare-both") (result i32) 279 (block (result i32) (f64.le (br 0 (i32.const 44)))) 280 ) 281 282 (func (export "as-convert-operand") (result i32) 283 (block (result i32) (i32.wrap_i64 (br 0 (i32.const 41)))) 284 ) 285 286 (func (export "as-memory.grow-size") (result i32) 287 (block (result i32) (memory.grow (br 0 (i32.const 40)))) 288 ) 289 290 (func (export "nested-block-value") (result i32) 291 (i32.add 292 (i32.const 1) 293 (block (result i32) 294 (call $dummy) 295 (i32.add (i32.const 4) (br 0 (i32.const 8))) 296 ) 297 ) 298 ) 299 300 (func (export "nested-br-value") (result i32) 301 (i32.add 302 (i32.const 1) 303 (block (result i32) 304 (drop (i32.const 2)) 305 (drop 306 (block (result i32) 307 (drop (i32.const 4)) 308 (br 0 (br 1 (i32.const 8))) 309 ) 310 ) 311 (i32.const 16) 312 ) 313 ) 314 ) 315 316 (func (export "nested-br_if-value") (result i32) 317 (i32.add 318 (i32.const 1) 319 (block (result i32) 320 (drop (i32.const 2)) 321 (drop 322 (block (result i32) 323 (drop (i32.const 4)) 324 (drop (br_if 0 (br 1 (i32.const 8)) (i32.const 1))) 325 (i32.const 32) 326 ) 327 ) 328 (i32.const 16) 329 ) 330 ) 331 ) 332 333 (func (export "nested-br_if-value-cond") (result i32) 334 (i32.add 335 (i32.const 1) 336 (block (result i32) 337 (drop (i32.const 2)) 338 (drop (br_if 0 (i32.const 4) (br 0 (i32.const 8)))) 339 (i32.const 16) 340 ) 341 ) 342 ) 343 344 (func (export "nested-br_table-value") (result i32) 345 (i32.add 346 (i32.const 1) 347 (block (result i32) 348 (drop (i32.const 2)) 349 (drop 350 (block (result i32) 351 (drop (i32.const 4)) 352 (br_table 0 (br 1 (i32.const 8)) (i32.const 1)) 353 ) 354 ) 355 (i32.const 16) 356 ) 357 ) 358 ) 359 360 (func (export "nested-br_table-value-index") (result i32) 361 (i32.add 362 (i32.const 1) 363 (block (result i32) 364 (drop (i32.const 2)) 365 (br_table 0 (i32.const 4) (br 0 (i32.const 8))) 366 (i32.const 16) 367 ) 368 ) 369 ) 370 ) 371 372 (assert_return (invoke "type-i32")) 373 (assert_return (invoke "type-i64")) 374 (assert_return (invoke "type-f32")) 375 (assert_return (invoke "type-f64")) 376 (assert_return (invoke "type-i32-i32")) 377 (assert_return (invoke "type-i64-i64")) 378 (assert_return (invoke "type-f32-f32")) 379 (assert_return (invoke "type-f64-f64")) 380 381 (assert_return (invoke "type-i32-value") (i32.const 1)) 382 (assert_return (invoke "type-i64-value") (i64.const 2)) 383 (assert_return (invoke "type-f32-value") (f32.const 3)) 384 (assert_return (invoke "type-f64-value") (f64.const 4)) 385 (assert_return (invoke "type-f64-f64-value") (f64.const 4) (f64.const 5)) 386 387 (assert_return (invoke "as-block-first")) 388 (assert_return (invoke "as-block-mid")) 389 (assert_return (invoke "as-block-last")) 390 (assert_return (invoke "as-block-value") (i32.const 2)) 391 392 (assert_return (invoke "as-loop-first") (i32.const 3)) 393 (assert_return (invoke "as-loop-mid") (i32.const 4)) 394 (assert_return (invoke "as-loop-last") (i32.const 5)) 395 396 (assert_return (invoke "as-br-value") (i32.const 9)) 397 398 (assert_return (invoke "as-br_if-cond")) 399 (assert_return (invoke "as-br_if-value") (i32.const 8)) 400 (assert_return (invoke "as-br_if-value-cond") (i32.const 9)) 401 402 (assert_return (invoke "as-br_table-index")) 403 (assert_return (invoke "as-br_table-value") (i32.const 10)) 404 (assert_return (invoke "as-br_table-value-index") (i32.const 11)) 405 406 (assert_return (invoke "as-return-value") (i64.const 7)) 407 (assert_return (invoke "as-return-values") (i32.const 2) (i64.const 7)) 408 409 (assert_return (invoke "as-if-cond") (i32.const 2)) 410 (assert_return (invoke "as-if-then" (i32.const 1) (i32.const 6)) (i32.const 3)) 411 (assert_return (invoke "as-if-then" (i32.const 0) (i32.const 6)) (i32.const 6)) 412 (assert_return (invoke "as-if-else" (i32.const 0) (i32.const 6)) (i32.const 4)) 413 (assert_return (invoke "as-if-else" (i32.const 1) (i32.const 6)) (i32.const 6)) 414 415 (assert_return (invoke "as-select-first" (i32.const 0) (i32.const 6)) (i32.const 5)) 416 (assert_return (invoke "as-select-first" (i32.const 1) (i32.const 6)) (i32.const 5)) 417 (assert_return (invoke "as-select-second" (i32.const 0) (i32.const 6)) (i32.const 6)) 418 (assert_return (invoke "as-select-second" (i32.const 1) (i32.const 6)) (i32.const 6)) 419 (assert_return (invoke "as-select-cond") (i32.const 7)) 420 (assert_return (invoke "as-select-all") (i32.const 8)) 421 422 (assert_return (invoke "as-call-first") (i32.const 12)) 423 (assert_return (invoke "as-call-mid") (i32.const 13)) 424 (assert_return (invoke "as-call-last") (i32.const 14)) 425 (assert_return (invoke "as-call-all") (i32.const 15)) 426 427 (assert_return (invoke "as-call_indirect-func") (i32.const 20)) 428 (assert_return (invoke "as-call_indirect-first") (i32.const 21)) 429 (assert_return (invoke "as-call_indirect-mid") (i32.const 22)) 430 (assert_return (invoke "as-call_indirect-last") (i32.const 23)) 431 (assert_return (invoke "as-call_indirect-all") (i32.const 24)) 432 433 (assert_return (invoke "as-local.set-value") (i32.const 17)) 434 (assert_return (invoke "as-local.tee-value") (i32.const 1)) 435 (assert_return (invoke "as-global.set-value") (i32.const 1)) 436 437 (assert_return (invoke "as-load-address") (f32.const 1.7)) 438 (assert_return (invoke "as-loadN-address") (i64.const 30)) 439 440 (assert_return (invoke "as-store-address") (i32.const 30)) 441 (assert_return (invoke "as-store-value") (i32.const 31)) 442 (assert_return (invoke "as-store-both") (i32.const 32)) 443 (assert_return (invoke "as-storeN-address") (i32.const 32)) 444 (assert_return (invoke "as-storeN-value") (i32.const 33)) 445 (assert_return (invoke "as-storeN-both") (i32.const 34)) 446 447 (assert_return (invoke "as-unary-operand") (f32.const 3.4)) 448 449 (assert_return (invoke "as-binary-left") (i32.const 3)) 450 (assert_return (invoke "as-binary-right") (i64.const 45)) 451 (assert_return (invoke "as-binary-both") (i32.const 46)) 452 453 (assert_return (invoke "as-test-operand") (i32.const 44)) 454 455 (assert_return (invoke "as-compare-left") (i32.const 43)) 456 (assert_return (invoke "as-compare-right") (i32.const 42)) 457 (assert_return (invoke "as-compare-both") (i32.const 44)) 458 459 (assert_return (invoke "as-convert-operand") (i32.const 41)) 460 461 (assert_return (invoke "as-memory.grow-size") (i32.const 40)) 462 463 (assert_return (invoke "nested-block-value") (i32.const 9)) 464 (assert_return (invoke "nested-br-value") (i32.const 9)) 465 (assert_return (invoke "nested-br_if-value") (i32.const 9)) 466 (assert_return (invoke "nested-br_if-value-cond") (i32.const 9)) 467 (assert_return (invoke "nested-br_table-value") (i32.const 9)) 468 (assert_return (invoke "nested-br_table-value-index") (i32.const 9)) 469 470 (assert_invalid 471 (module (func $type-arg-empty-vs-num (result i32) 472 (block (result i32) (br 0) (i32.const 1)) 473 )) 474 "type mismatch" 475 ) 476 477 (assert_invalid 478 (module (func $type-arg-void-vs-num (result i32) 479 (block (result i32) (br 0 (nop)) (i32.const 1)) 480 )) 481 "type mismatch" 482 ) 483 (assert_invalid 484 (module (func $type-arg-void-vs-num-nested (result i32) 485 (block (result i32) (i32.const 0) (block (br 1))) 486 )) 487 "type mismatch" 488 ) 489 (assert_invalid 490 (module (func $type-arg-num-vs-num (result i32) 491 (block (result i32) (br 0 (i64.const 1)) (i32.const 1)) 492 )) 493 "type mismatch" 494 ) 495 496 (assert_invalid 497 (module 498 (func $type-arg-empty-in-br 499 (i32.const 0) 500 (block (result i32) (br 0 (br 0))) (i32.eqz) (drop) 501 ) 502 ) 503 "type mismatch" 504 ) 505 (assert_invalid 506 (module 507 (func $type-arg-empty-in-br_if 508 (i32.const 0) 509 (block (result i32) (br_if 0 (br 0) (i32.const 1))) (i32.eqz) (drop) 510 ) 511 ) 512 "type mismatch" 513 ) 514 (assert_invalid 515 (module 516 (func $type-arg-empty-in-br_table 517 (i32.const 0) 518 (block (result i32) (br_table 0 (br 0))) (i32.eqz) (drop) 519 ) 520 ) 521 "type mismatch" 522 ) 523 (assert_invalid 524 (module 525 (func $type-arg-empty-in-return 526 (block (result i32) 527 (return (br 0)) 528 ) 529 (i32.eqz) (drop) 530 ) 531 ) 532 "type mismatch" 533 ) 534 (assert_invalid 535 (module 536 (func $type-arg-empty-in-select 537 (block (result i32) 538 (select (br 0) (i32.const 1) (i32.const 2)) 539 ) 540 (i32.eqz) (drop) 541 ) 542 ) 543 "type mismatch" 544 ) 545 (assert_invalid 546 (module 547 (func $type-arg-empty-in-call 548 (block (result i32) 549 (call 1 (br 0)) 550 ) 551 (i32.eqz) (drop) 552 ) 553 (func (param i32) (result i32) (local.get 0)) 554 ) 555 "type mismatch" 556 ) 557 (assert_invalid 558 (module 559 (func $f (param i32) (result i32) (local.get 0)) 560 (type $sig (func (param i32) (result i32))) 561 (table funcref (elem $f)) 562 (func $type-arg-empty-in-call_indirect 563 (block (result i32) 564 (call_indirect (type $sig) 565 (br 0) (i32.const 0) 566 ) 567 ) 568 (i32.eqz) (drop) 569 ) 570 ) 571 "type mismatch" 572 ) 573 (assert_invalid 574 (module 575 (func $type-arg-empty-in-local.set 576 (local i32) 577 (block (result i32) 578 (local.set 0 (br 0)) (local.get 0) 579 ) 580 (i32.eqz) (drop) 581 ) 582 ) 583 "type mismatch" 584 ) 585 (assert_invalid 586 (module 587 (func $type-arg-empty-in-local.tee 588 (local i32) 589 (block (result i32) 590 (local.tee 0 (br 0)) 591 ) 592 (i32.eqz) (drop) 593 ) 594 ) 595 "type mismatch" 596 ) 597 (assert_invalid 598 (module 599 (global $x (mut i32) (i32.const 0)) 600 (func $type-arg-empty-in-global.set 601 (block (result i32) 602 (global.set $x (br 0)) (global.get $x) 603 ) 604 (i32.eqz) (drop) 605 ) 606 ) 607 "type mismatch" 608 ) 609 (assert_invalid 610 (module 611 (memory 0) 612 (func $type-arg-empty-in-memory.grow 613 (block (result i32) 614 (memory.grow (br 0)) 615 ) 616 (i32.eqz) (drop) 617 ) 618 ) 619 "type mismatch" 620 ) 621 (assert_invalid 622 (module 623 (memory 1) 624 (func $type-arg-empty-in-load 625 (block (result i32) 626 (i32.load (br 0)) 627 ) 628 (i32.eqz) (drop) 629 ) 630 ) 631 "type mismatch" 632 ) 633 (assert_invalid 634 (module 635 (memory 1) 636 (func $type-arg-empty-in-store 637 (block (result i32) 638 (i32.store (br 0) (i32.const 0)) 639 ) 640 (i32.eqz) (drop) 641 ) 642 ) 643 "type mismatch" 644 ) 645 646 (assert_invalid 647 (module (func $unbound-label (br 1))) 648 "unknown label" 649 ) 650 (assert_invalid 651 (module (func $unbound-nested-label (block (block (br 5))))) 652 "unknown label" 653 ) 654 (assert_invalid 655 (module (func $large-label (br 0x10000001))) 656 "unknown label" 657 )