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