...

Text file src/github.com/tetratelabs/wazero/internal/integration_test/spectest/v1/testdata/if.wast

Documentation: github.com/tetratelabs/wazero/internal/integration_test/spectest/v1/testdata

     1;; Test `if` operator
     2
     3(module
     4  ;; Auxiliary definition
     5  (memory 1)
     6
     7  (func $dummy)
     8
     9  (func (export "empty") (param i32)
    10    (if (local.get 0) (then))
    11    (if (local.get 0) (then) (else))
    12    (if $l (local.get 0) (then))
    13    (if $l (local.get 0) (then) (else))
    14  )
    15
    16  (func (export "singular") (param i32) (result i32)
    17    (if (local.get 0) (then (nop)))
    18    (if (local.get 0) (then (nop)) (else (nop)))
    19    (if (result i32) (local.get 0) (then (i32.const 7)) (else (i32.const 8)))
    20  )
    21
    22  (func (export "multi") (param i32) (result i32)
    23    (if (local.get 0) (then (call $dummy) (call $dummy) (call $dummy)))
    24    (if (local.get 0) (then) (else (call $dummy) (call $dummy) (call $dummy)))
    25    (if (result i32) (local.get 0)
    26      (then (call $dummy) (call $dummy) (i32.const 8))
    27      (else (call $dummy) (call $dummy) (i32.const 9))
    28    )
    29  )
    30
    31  (func (export "nested") (param i32 i32) (result i32)
    32    (if (result i32) (local.get 0)
    33      (then
    34        (if (local.get 1) (then (call $dummy) (block) (nop)))
    35        (if (local.get 1) (then) (else (call $dummy) (block) (nop)))
    36        (if (result i32) (local.get 1)
    37          (then (call $dummy) (i32.const 9))
    38          (else (call $dummy) (i32.const 10))
    39        )
    40      )
    41      (else
    42        (if (local.get 1) (then (call $dummy) (block) (nop)))
    43        (if (local.get 1) (then) (else (call $dummy) (block) (nop)))
    44        (if (result i32) (local.get 1)
    45          (then (call $dummy) (i32.const 10))
    46          (else (call $dummy) (i32.const 11))
    47        )
    48      )
    49    )
    50  )
    51
    52  (func (export "as-select-first") (param i32) (result i32)
    53    (select
    54      (if (result i32) (local.get 0)
    55        (then (call $dummy) (i32.const 1))
    56        (else (call $dummy) (i32.const 0))
    57      )
    58      (i32.const 2) (i32.const 3)
    59    )
    60  )
    61  (func (export "as-select-mid") (param i32) (result i32)
    62    (select
    63      (i32.const 2)
    64      (if (result i32) (local.get 0)
    65        (then (call $dummy) (i32.const 1))
    66        (else (call $dummy) (i32.const 0))
    67      )
    68      (i32.const 3)
    69    )
    70  )
    71  (func (export "as-select-last") (param i32) (result i32)
    72    (select
    73      (i32.const 2) (i32.const 3)
    74      (if (result i32) (local.get 0)
    75        (then (call $dummy) (i32.const 1))
    76        (else (call $dummy) (i32.const 0))
    77      )
    78    )
    79  )
    80
    81  (func (export "as-loop-first") (param i32) (result i32)
    82    (loop (result i32)
    83      (if (result i32) (local.get 0)
    84        (then (call $dummy) (i32.const 1))
    85        (else (call $dummy) (i32.const 0))
    86      )
    87      (call $dummy) (call $dummy)
    88    )
    89  )
    90  (func (export "as-loop-mid") (param i32) (result i32)
    91    (loop (result i32)
    92      (call $dummy)
    93      (if (result i32) (local.get 0)
    94        (then (call $dummy) (i32.const 1))
    95        (else (call $dummy) (i32.const 0))
    96      )
    97      (call $dummy)
    98    )
    99  )
   100  (func (export "as-loop-last") (param i32) (result i32)
   101    (loop (result i32)
   102      (call $dummy) (call $dummy)
   103      (if (result i32) (local.get 0)
   104        (then (call $dummy) (i32.const 1))
   105        (else (call $dummy) (i32.const 0))
   106      )
   107    )
   108  )
   109
   110  (func (export "as-if-condition") (param i32) (result i32)
   111    (if (result i32)
   112      (if (result i32) (local.get 0)
   113        (then (i32.const 1)) (else (i32.const 0))
   114      )
   115      (then (call $dummy) (i32.const 2))
   116      (else (call $dummy) (i32.const 3))
   117    )
   118  )
   119
   120  (func (export "as-br_if-first") (param i32) (result i32)
   121    (block (result i32)
   122      (br_if 0
   123        (if (result i32) (local.get 0)
   124          (then (call $dummy) (i32.const 1))
   125          (else (call $dummy) (i32.const 0))
   126        )
   127        (i32.const 2)
   128      )
   129      (return (i32.const 3))
   130    )
   131  )
   132  (func (export "as-br_if-last") (param i32) (result i32)
   133    (block (result i32)
   134      (br_if 0
   135        (i32.const 2)
   136        (if (result i32) (local.get 0)
   137          (then (call $dummy) (i32.const 1))
   138          (else (call $dummy) (i32.const 0))
   139        )
   140      )
   141      (return (i32.const 3))
   142    )
   143  )
   144
   145  (func (export "as-br_table-first") (param i32) (result i32)
   146    (block (result i32)
   147      (if (result i32) (local.get 0)
   148        (then (call $dummy) (i32.const 1))
   149        (else (call $dummy) (i32.const 0))
   150      )
   151      (i32.const 2)
   152      (br_table 0 0)
   153    )
   154  )
   155  (func (export "as-br_table-last") (param i32) (result i32)
   156    (block (result i32)
   157      (i32.const 2)
   158      (if (result i32) (local.get 0)
   159        (then (call $dummy) (i32.const 1))
   160        (else (call $dummy) (i32.const 0))
   161      )
   162      (br_table 0 0)
   163    )
   164  )
   165
   166  (func $func (param i32 i32) (result i32) (local.get 0))
   167  (type $check (func (param i32 i32) (result i32)))
   168  (table funcref (elem $func))
   169  (func (export "as-call_indirect-first") (param i32) (result i32)
   170    (block (result i32)
   171      (call_indirect (type $check)
   172        (if (result i32) (local.get 0)
   173          (then (call $dummy) (i32.const 1))
   174          (else (call $dummy) (i32.const 0))
   175        )
   176        (i32.const 2) (i32.const 0)
   177      )
   178    )
   179  )
   180  (func (export "as-call_indirect-mid") (param i32) (result i32)
   181    (block (result i32)
   182      (call_indirect (type $check)
   183        (i32.const 2)
   184        (if (result i32) (local.get 0)
   185          (then (call $dummy) (i32.const 1))
   186          (else (call $dummy) (i32.const 0))
   187        )
   188        (i32.const 0)
   189      )
   190    )
   191  )
   192  (func (export "as-call_indirect-last") (param i32) (result i32)
   193    (block (result i32)
   194      (call_indirect (type $check)
   195        (i32.const 2) (i32.const 0)
   196        (if (result i32) (local.get 0)
   197          (then (call $dummy) (i32.const 1))
   198          (else (call $dummy) (i32.const 0))
   199        )
   200      )
   201    )
   202  )
   203
   204  (func (export "as-store-first") (param i32)
   205    (if (result i32) (local.get 0)
   206      (then (call $dummy) (i32.const 1))
   207      (else (call $dummy) (i32.const 0))
   208    )
   209    (i32.const 2)
   210    (i32.store)
   211  )
   212  (func (export "as-store-last") (param i32)
   213    (i32.const 2)
   214    (if (result i32) (local.get 0)
   215      (then (call $dummy) (i32.const 1))
   216      (else (call $dummy) (i32.const 0))
   217    )
   218    (i32.store)
   219  )
   220
   221  (func (export "as-memory.grow-value") (param i32) (result i32)
   222    (memory.grow
   223      (if (result i32) (local.get 0)
   224        (then (i32.const 1))
   225        (else (i32.const 0))
   226      )
   227    )
   228  )
   229
   230  (func $f (param i32) (result i32) (local.get 0))
   231
   232  (func (export "as-call-value") (param i32) (result i32)
   233    (call $f
   234      (if (result i32) (local.get 0)
   235        (then (i32.const 1))
   236        (else (i32.const 0))
   237      )
   238    )
   239  )
   240  (func (export "as-return-value") (param i32) (result i32)
   241    (if (result i32) (local.get 0)
   242      (then (i32.const 1))
   243      (else (i32.const 0)))
   244    (return)
   245  )
   246  (func (export "as-drop-operand") (param i32)
   247    (drop
   248      (if (result i32) (local.get 0)
   249        (then (i32.const 1))
   250        (else (i32.const 0))
   251      )
   252    )
   253  )
   254  (func (export "as-br-value") (param i32) (result i32)
   255    (block (result i32)
   256      (br 0
   257        (if (result i32) (local.get 0)
   258          (then (i32.const 1))
   259          (else (i32.const 0))
   260        )
   261      )
   262    )
   263  )
   264  (func (export "as-local.set-value") (param i32) (result i32)
   265    (local i32)
   266    (local.set 0
   267      (if (result i32) (local.get 0)
   268        (then (i32.const 1))
   269        (else (i32.const 0))
   270      )
   271    )
   272    (local.get 0)
   273  )
   274  (func (export "as-local.tee-value") (param i32) (result i32)
   275    (local.tee 0
   276      (if (result i32) (local.get 0)
   277        (then (i32.const 1))
   278        (else (i32.const 0))
   279      )
   280    )
   281  )
   282  (global $a (mut i32) (i32.const 10))
   283  (func (export "as-global.set-value") (param i32) (result i32)
   284    (global.set $a
   285      (if (result i32) (local.get 0)
   286        (then (i32.const 1))
   287        (else (i32.const 0))
   288      )
   289    ) (global.get $a)
   290  )
   291  (func (export "as-load-operand") (param i32) (result i32)
   292    (i32.load
   293      (if (result i32) (local.get 0)
   294        (then (i32.const 11))
   295        (else (i32.const 10))
   296      )
   297    )
   298  )
   299
   300  (func (export "as-unary-operand") (param i32) (result i32)
   301    (i32.ctz
   302      (if (result i32) (local.get 0)
   303        (then (call $dummy) (i32.const 13))
   304        (else (call $dummy) (i32.const -13))
   305      )
   306    )
   307  )
   308  (func (export "as-binary-operand") (param i32 i32) (result i32)
   309    (i32.mul
   310      (if (result i32) (local.get 0)
   311        (then (call $dummy) (i32.const 3))
   312        (else (call $dummy) (i32.const -3))
   313      )
   314      (if (result i32) (local.get 1)
   315        (then (call $dummy) (i32.const 4))
   316        (else (call $dummy) (i32.const -5))
   317      )
   318    )
   319  )
   320  (func (export "as-test-operand") (param i32) (result i32)
   321    (i32.eqz
   322      (if (result i32) (local.get 0)
   323        (then (call $dummy) (i32.const 13))
   324        (else (call $dummy) (i32.const 0))
   325      )
   326    )
   327  )
   328  (func (export "as-compare-operand") (param i32 i32) (result i32)
   329    (f32.gt
   330      (if (result f32) (local.get 0)
   331        (then (call $dummy) (f32.const 3))
   332        (else (call $dummy) (f32.const -3))
   333      )
   334      (if (result f32) (local.get 1)
   335        (then (call $dummy) (f32.const 4))
   336        (else (call $dummy) (f32.const -4))
   337      )
   338    )
   339  )
   340
   341  (func (export "break-bare") (result i32)
   342    (if (i32.const 1) (then (br 0) (unreachable)))
   343    (if (i32.const 1) (then (br 0) (unreachable)) (else (unreachable)))
   344    (if (i32.const 0) (then (unreachable)) (else (br 0) (unreachable)))
   345    (if (i32.const 1) (then (br_if 0 (i32.const 1)) (unreachable)))
   346    (if (i32.const 1) (then (br_if 0 (i32.const 1)) (unreachable)) (else (unreachable)))
   347    (if (i32.const 0) (then (unreachable)) (else (br_if 0 (i32.const 1)) (unreachable)))
   348    (if (i32.const 1) (then (br_table 0 (i32.const 0)) (unreachable)))
   349    (if (i32.const 1) (then (br_table 0 (i32.const 0)) (unreachable)) (else (unreachable)))
   350    (if (i32.const 0) (then (unreachable)) (else (br_table 0 (i32.const 0)) (unreachable)))
   351    (i32.const 19)
   352  )
   353
   354  (func (export "break-value") (param i32) (result i32)
   355    (if (result i32) (local.get 0)
   356      (then (br 0 (i32.const 18)) (i32.const 19))
   357      (else (br 0 (i32.const 21)) (i32.const 20))
   358    )
   359  )
   360
   361  (func (export "effects") (param i32) (result i32)
   362    (local i32)
   363    (if
   364      (block (result i32) (local.set 1 (i32.const 1)) (local.get 0))
   365      (then
   366        (local.set 1 (i32.mul (local.get 1) (i32.const 3)))
   367        (local.set 1 (i32.sub (local.get 1) (i32.const 5)))
   368        (local.set 1 (i32.mul (local.get 1) (i32.const 7)))
   369        (br 0)
   370        (local.set 1 (i32.mul (local.get 1) (i32.const 100)))
   371      )
   372      (else
   373        (local.set 1 (i32.mul (local.get 1) (i32.const 5)))
   374        (local.set 1 (i32.sub (local.get 1) (i32.const 7)))
   375        (local.set 1 (i32.mul (local.get 1) (i32.const 3)))
   376        (br 0)
   377        (local.set 1 (i32.mul (local.get 1) (i32.const 1000)))
   378      )
   379    )
   380    (local.get 1)
   381  )
   382)
   383
   384(assert_return (invoke "empty" (i32.const 0)))
   385(assert_return (invoke "empty" (i32.const 1)))
   386(assert_return (invoke "empty" (i32.const 100)))
   387(assert_return (invoke "empty" (i32.const -2)))
   388
   389(assert_return (invoke "singular" (i32.const 0)) (i32.const 8))
   390(assert_return (invoke "singular" (i32.const 1)) (i32.const 7))
   391(assert_return (invoke "singular" (i32.const 10)) (i32.const 7))
   392(assert_return (invoke "singular" (i32.const -10)) (i32.const 7))
   393
   394(assert_return (invoke "multi" (i32.const 0)) (i32.const 9))
   395(assert_return (invoke "multi" (i32.const 1)) (i32.const 8))
   396(assert_return (invoke "multi" (i32.const 13)) (i32.const 8))
   397(assert_return (invoke "multi" (i32.const -5)) (i32.const 8))
   398
   399(assert_return (invoke "nested" (i32.const 0) (i32.const 0)) (i32.const 11))
   400(assert_return (invoke "nested" (i32.const 1) (i32.const 0)) (i32.const 10))
   401(assert_return (invoke "nested" (i32.const 0) (i32.const 1)) (i32.const 10))
   402(assert_return (invoke "nested" (i32.const 3) (i32.const 2)) (i32.const 9))
   403(assert_return (invoke "nested" (i32.const 0) (i32.const -100)) (i32.const 10))
   404(assert_return (invoke "nested" (i32.const 10) (i32.const 10)) (i32.const 9))
   405(assert_return (invoke "nested" (i32.const 0) (i32.const -1)) (i32.const 10))
   406(assert_return (invoke "nested" (i32.const -111) (i32.const -2)) (i32.const 9))
   407
   408(assert_return (invoke "as-select-first" (i32.const 0)) (i32.const 0))
   409(assert_return (invoke "as-select-first" (i32.const 1)) (i32.const 1))
   410(assert_return (invoke "as-select-mid" (i32.const 0)) (i32.const 2))
   411(assert_return (invoke "as-select-mid" (i32.const 1)) (i32.const 2))
   412(assert_return (invoke "as-select-last" (i32.const 0)) (i32.const 3))
   413(assert_return (invoke "as-select-last" (i32.const 1)) (i32.const 2))
   414
   415(assert_return (invoke "as-loop-first" (i32.const 0)) (i32.const 0))
   416(assert_return (invoke "as-loop-first" (i32.const 1)) (i32.const 1))
   417(assert_return (invoke "as-loop-mid" (i32.const 0)) (i32.const 0))
   418(assert_return (invoke "as-loop-mid" (i32.const 1)) (i32.const 1))
   419(assert_return (invoke "as-loop-last" (i32.const 0)) (i32.const 0))
   420(assert_return (invoke "as-loop-last" (i32.const 1)) (i32.const 1))
   421
   422(assert_return (invoke "as-if-condition" (i32.const 0)) (i32.const 3))
   423(assert_return (invoke "as-if-condition" (i32.const 1)) (i32.const 2))
   424
   425(assert_return (invoke "as-br_if-first" (i32.const 0)) (i32.const 0))
   426(assert_return (invoke "as-br_if-first" (i32.const 1)) (i32.const 1))
   427(assert_return (invoke "as-br_if-last" (i32.const 0)) (i32.const 3))
   428(assert_return (invoke "as-br_if-last" (i32.const 1)) (i32.const 2))
   429
   430(assert_return (invoke "as-br_table-first" (i32.const 0)) (i32.const 0))
   431(assert_return (invoke "as-br_table-first" (i32.const 1)) (i32.const 1))
   432(assert_return (invoke "as-br_table-last" (i32.const 0)) (i32.const 2))
   433(assert_return (invoke "as-br_table-last" (i32.const 1)) (i32.const 2))
   434
   435(assert_return (invoke "as-call_indirect-first" (i32.const 0)) (i32.const 0))
   436(assert_return (invoke "as-call_indirect-first" (i32.const 1)) (i32.const 1))
   437(assert_return (invoke "as-call_indirect-mid" (i32.const 0)) (i32.const 2))
   438(assert_return (invoke "as-call_indirect-mid" (i32.const 1)) (i32.const 2))
   439(assert_return (invoke "as-call_indirect-last" (i32.const 0)) (i32.const 2))
   440(assert_trap (invoke "as-call_indirect-last" (i32.const 1)) "undefined element")
   441
   442(assert_return (invoke "as-store-first" (i32.const 0)))
   443(assert_return (invoke "as-store-first" (i32.const 1)))
   444(assert_return (invoke "as-store-last" (i32.const 0)))
   445(assert_return (invoke "as-store-last" (i32.const 1)))
   446
   447(assert_return (invoke "as-memory.grow-value" (i32.const 0)) (i32.const 1))
   448(assert_return (invoke "as-memory.grow-value" (i32.const 1)) (i32.const 1))
   449
   450(assert_return (invoke "as-call-value" (i32.const 0)) (i32.const 0))
   451(assert_return (invoke "as-call-value" (i32.const 1)) (i32.const 1))
   452
   453(assert_return (invoke "as-return-value" (i32.const 0)) (i32.const 0))
   454(assert_return (invoke "as-return-value" (i32.const 1)) (i32.const 1))
   455
   456(assert_return (invoke "as-drop-operand" (i32.const 0)))
   457(assert_return (invoke "as-drop-operand" (i32.const 1)))
   458
   459(assert_return (invoke "as-br-value" (i32.const 0)) (i32.const 0))
   460(assert_return (invoke "as-br-value" (i32.const 1)) (i32.const 1))
   461
   462(assert_return (invoke "as-local.set-value" (i32.const 0)) (i32.const 0))
   463(assert_return (invoke "as-local.set-value" (i32.const 1)) (i32.const 1))
   464
   465(assert_return (invoke "as-local.tee-value" (i32.const 0)) (i32.const 0))
   466(assert_return (invoke "as-local.tee-value" (i32.const 1)) (i32.const 1))
   467
   468(assert_return (invoke "as-global.set-value" (i32.const 0)) (i32.const 0))
   469(assert_return (invoke "as-global.set-value" (i32.const 1)) (i32.const 1))
   470
   471(assert_return (invoke "as-load-operand" (i32.const 0)) (i32.const 0))
   472(assert_return (invoke "as-load-operand" (i32.const 1)) (i32.const 0))
   473
   474(assert_return (invoke "as-unary-operand" (i32.const 0)) (i32.const 0))
   475(assert_return (invoke "as-unary-operand" (i32.const 1)) (i32.const 0))
   476(assert_return (invoke "as-unary-operand" (i32.const -1)) (i32.const 0))
   477
   478(assert_return (invoke "as-binary-operand" (i32.const 0) (i32.const 0)) (i32.const 15))
   479(assert_return (invoke "as-binary-operand" (i32.const 0) (i32.const 1)) (i32.const -12))
   480(assert_return (invoke "as-binary-operand" (i32.const 1) (i32.const 0)) (i32.const -15))
   481(assert_return (invoke "as-binary-operand" (i32.const 1) (i32.const 1)) (i32.const 12))
   482
   483(assert_return (invoke "as-test-operand" (i32.const 0)) (i32.const 1))
   484(assert_return (invoke "as-test-operand" (i32.const 1)) (i32.const 0))
   485
   486(assert_return (invoke "as-compare-operand" (i32.const 0) (i32.const 0)) (i32.const 1))
   487(assert_return (invoke "as-compare-operand" (i32.const 0) (i32.const 1)) (i32.const 0))
   488(assert_return (invoke "as-compare-operand" (i32.const 1) (i32.const 0)) (i32.const 1))
   489(assert_return (invoke "as-compare-operand" (i32.const 1) (i32.const 1)) (i32.const 0))
   490
   491(assert_return (invoke "break-bare") (i32.const 19))
   492(assert_return (invoke "break-value" (i32.const 1)) (i32.const 18))
   493(assert_return (invoke "break-value" (i32.const 0)) (i32.const 21))
   494
   495(assert_return (invoke "effects" (i32.const 1)) (i32.const -14))
   496(assert_return (invoke "effects" (i32.const 0)) (i32.const -6))
   497
   498(assert_invalid
   499  (module (func $type-empty-i32 (result i32) (if (i32.const 0) (then))))
   500  "type mismatch"
   501)
   502(assert_invalid
   503  (module (func $type-empty-i64 (result i64) (if (i32.const 0) (then))))
   504  "type mismatch"
   505)
   506(assert_invalid
   507  (module (func $type-empty-f32 (result f32) (if (i32.const 0) (then))))
   508  "type mismatch"
   509)
   510(assert_invalid
   511  (module (func $type-empty-f64 (result f64) (if (i32.const 0) (then))))
   512  "type mismatch"
   513)
   514
   515(assert_invalid
   516  (module (func $type-empty-i32 (result i32) (if (i32.const 0) (then) (else))))
   517  "type mismatch"
   518)
   519(assert_invalid
   520  (module (func $type-empty-i64 (result i64) (if (i32.const 0) (then) (else))))
   521  "type mismatch"
   522)
   523(assert_invalid
   524  (module (func $type-empty-f32 (result f32) (if (i32.const 0) (then) (else))))
   525  "type mismatch"
   526)
   527(assert_invalid
   528  (module (func $type-empty-f64 (result f64) (if (i32.const 0) (then) (else))))
   529  "type mismatch"
   530)
   531
   532(assert_invalid
   533  (module (func $type-then-value-num-vs-void
   534    (if (i32.const 1) (then (i32.const 1)))
   535  ))
   536  "type mismatch"
   537)
   538(assert_invalid
   539  (module (func $type-then-value-num-vs-void
   540    (if (i32.const 1) (then (i32.const 1)) (else))
   541  ))
   542  "type mismatch"
   543)
   544(assert_invalid
   545  (module (func $type-else-value-num-vs-void
   546    (if (i32.const 1) (then) (else (i32.const 1)))
   547  ))
   548  "type mismatch"
   549)
   550(assert_invalid
   551  (module (func $type-both-value-num-vs-void
   552    (if (i32.const 1) (then (i32.const 1)) (else (i32.const 1)))
   553  ))
   554  "type mismatch"
   555)
   556
   557(assert_invalid
   558  (module (func $type-then-value-empty-vs-num (result i32)
   559    (if (result i32) (i32.const 1) (then) (else (i32.const 0)))
   560  ))
   561  "type mismatch"
   562)
   563(assert_invalid
   564  (module (func $type-then-value-empty-vs-num (result i32)
   565    (if (result i32) (i32.const 1) (then (i32.const 0)) (else))
   566  ))
   567  "type mismatch"
   568)
   569(assert_invalid
   570  (module (func $type-both-value-empty-vs-num (result i32)
   571    (if (result i32) (i32.const 1) (then) (else))
   572  ))
   573  "type mismatch"
   574)
   575(assert_invalid
   576  (module (func $type-no-else-vs-num (result i32)
   577    (if (result i32) (i32.const 1) (then (i32.const 1)))
   578  ))
   579  "type mismatch"
   580)
   581
   582(assert_invalid
   583  (module (func $type-then-value-void-vs-num (result i32)
   584    (if (result i32) (i32.const 1) (then (nop)) (else (i32.const 0)))
   585  ))
   586  "type mismatch"
   587)
   588(assert_invalid
   589  (module (func $type-then-value-void-vs-num (result i32)
   590    (if (result i32) (i32.const 1) (then (i32.const 0)) (else (nop)))
   591  ))
   592  "type mismatch"
   593)
   594(assert_invalid
   595  (module (func $type-both-value-void-vs-num (result i32)
   596    (if (result i32) (i32.const 1) (then (nop)) (else (nop)))
   597  ))
   598  "type mismatch"
   599)
   600
   601(assert_invalid
   602  (module (func $type-then-value-num-vs-num (result i32)
   603    (if (result i32) (i32.const 1) (then (i64.const 1)) (else (i32.const 1)))
   604  ))
   605  "type mismatch"
   606)
   607(assert_invalid
   608  (module (func $type-then-value-num-vs-num (result i32)
   609    (if (result i32) (i32.const 1) (then (i32.const 1)) (else (i64.const 1)))
   610  ))
   611  "type mismatch"
   612)
   613(assert_invalid
   614  (module (func $type-both-value-num-vs-num (result i32)
   615    (if (result i32) (i32.const 1) (then (i64.const 1)) (else (i64.const 1)))
   616  ))
   617  "type mismatch"
   618)
   619(assert_invalid
   620  (module (func $type-both-different-value-num-vs-num (result i32)
   621    (if (result i32) (i32.const 1) (then (i64.const 1)) (else (f64.const 1)))
   622  ))
   623  "type mismatch"
   624)
   625
   626(assert_invalid
   627  (module (func $type-then-value-unreached-select (result i32)
   628    (if (result i64)
   629      (i32.const 0)
   630      (then (select (unreachable) (unreachable) (unreachable)))
   631      (else (i64.const 0))
   632    )
   633  ))
   634  "type mismatch"
   635)
   636(assert_invalid
   637  (module (func $type-else-value-unreached-select (result i32)
   638    (if (result i64)
   639      (i32.const 1)
   640      (then (i64.const 0))
   641      (else (select (unreachable) (unreachable) (unreachable)))
   642    )
   643  ))
   644  "type mismatch"
   645)
   646(assert_invalid
   647  (module (func $type-else-value-unreached-select (result i32)
   648    (if (result i64)
   649      (i32.const 1)
   650      (then (select (unreachable) (unreachable) (unreachable)))
   651      (else (select (unreachable) (unreachable) (unreachable)))
   652    )
   653  ))
   654  "type mismatch"
   655)
   656
   657(assert_invalid
   658  (module (func $type-then-break-last-void-vs-num (result i32)
   659    (if (result i32) (i32.const 1) (then (br 0)) (else (i32.const 1)))
   660  ))
   661  "type mismatch"
   662)
   663(assert_invalid
   664  (module (func $type-else-break-last-void-vs-num (result i32)
   665    (if (result i32) (i32.const 1) (then (i32.const 1)) (else (br 0)))
   666  ))
   667  "type mismatch"
   668)
   669(assert_invalid
   670  (module (func $type-then-break-empty-vs-num (result i32)
   671    (if (result i32) (i32.const 1)
   672      (then (br 0) (i32.const 1))
   673      (else (i32.const 1))
   674    )
   675  ))
   676  "type mismatch"
   677)
   678(assert_invalid
   679  (module (func $type-else-break-empty-vs-num (result i32)
   680    (if (result i32) (i32.const 1)
   681      (then (i32.const 1))
   682      (else (br 0) (i32.const 1))
   683    )
   684  ))
   685  "type mismatch"
   686)
   687(assert_invalid
   688  (module (func $type-then-break-void-vs-num (result i32)
   689    (if (result i32) (i32.const 1)
   690      (then (br 0 (nop)) (i32.const 1))
   691      (else (i32.const 1))
   692    )
   693  ))
   694  "type mismatch"
   695)
   696(assert_invalid
   697  (module (func $type-else-break-void-vs-num (result i32)
   698    (if (result i32) (i32.const 1)
   699      (then (i32.const 1))
   700      (else (br 0 (nop)) (i32.const 1))
   701    )
   702  ))
   703  "type mismatch"
   704)
   705
   706(assert_invalid
   707  (module (func $type-then-break-num-vs-num (result i32)
   708    (if (result i32) (i32.const 1)
   709      (then (br 0 (i64.const 1)) (i32.const 1))
   710      (else (i32.const 1))
   711    )
   712  ))
   713  "type mismatch"
   714)
   715(assert_invalid
   716  (module (func $type-else-break-num-vs-num (result i32)
   717    (if (result i32) (i32.const 1)
   718      (then (i32.const 1))
   719      (else (br 0 (i64.const 1)) (i32.const 1))
   720    )
   721  ))
   722  "type mismatch"
   723)
   724
   725(assert_invalid
   726  (module
   727    (func $type-condition-empty
   728      (if (then))
   729    )
   730  )
   731  "type mismatch"
   732)
   733(assert_invalid
   734  (module
   735    (func $type-condition-empty-in-block
   736      (i32.const 0)
   737      (block (if (then)))
   738    )
   739  )
   740  "type mismatch"
   741)
   742(assert_invalid
   743  (module
   744    (func $type-condition-empty-in-loop
   745      (i32.const 0)
   746      (loop (if (then)))
   747    )
   748  )
   749  "type mismatch"
   750)
   751(assert_invalid
   752  (module
   753    (func $type-condition-empty-in-then
   754      (i32.const 0) (i32.const 0)
   755      (if (then (if (then))))
   756    )
   757  )
   758  "type mismatch"
   759)
   760(assert_invalid
   761  (module
   762    (func $type-condition-empty-in-else
   763      (i32.const 0) (i32.const 0)
   764      (if (result i32) (then (i32.const 0)) (else (if (then)) (i32.const 0)))
   765      (drop)
   766    )
   767  )
   768  "type mismatch"
   769)
   770(assert_invalid
   771  (module
   772    (func $type-condition-empty-in-br
   773      (i32.const 0)
   774      (block (br 0 (if(then))) (drop))
   775    )
   776  )
   777  "type mismatch"
   778)
   779(assert_invalid
   780  (module
   781    (func $type-condition-empty-in-br_if
   782      (i32.const 0)
   783      (block (br_if 0 (if(then)) (i32.const 1)) (drop))
   784    )
   785  )
   786  "type mismatch"
   787)
   788(assert_invalid
   789  (module
   790    (func $type-condition-empty-in-br_table
   791      (i32.const 0)
   792      (block (br_table 0 (if(then))) (drop))
   793    )
   794  )
   795  "type mismatch"
   796)
   797(assert_invalid
   798  (module
   799    (func $type-condition-empty-in-return
   800      (return (if(then))) (drop)
   801    )
   802  )
   803  "type mismatch"
   804)
   805(assert_invalid
   806  (module
   807    (func $type-condition-empty-in-select
   808      (select (if(then)) (i32.const 1) (i32.const 2)) (drop)
   809    )
   810  )
   811  "type mismatch"
   812)
   813(assert_invalid
   814  (module
   815    (func $type-condition-empty-in-call
   816      (call 1 (if(then))) (drop)
   817    )
   818    (func (param i32) (result i32) (local.get 0))
   819  )
   820  "type mismatch"
   821)
   822(assert_invalid
   823  (module
   824    (func $f (param i32) (result i32) (local.get 0))
   825    (type $sig (func (param i32) (result i32)))
   826    (table funcref (elem $f))
   827    (func $type-condition-empty-in-call_indirect
   828      (block (result i32)
   829        (call_indirect (type $sig)
   830          (if(then)) (i32.const 0)
   831        )
   832        (drop)
   833      )
   834    )
   835  )
   836  "type mismatch"
   837)
   838(assert_invalid
   839  (module
   840    (func $type-condition-empty-in-local.set
   841      (local i32)
   842      (local.set 0 (if(then))) (local.get 0) (drop)
   843    )
   844  )
   845  "type mismatch"
   846)
   847(assert_invalid
   848  (module
   849    (func $type-condition-empty-in-local.tee
   850      (local i32)
   851      (local.tee 0 (if(then))) (drop)
   852    )
   853  )
   854  "type mismatch"
   855)
   856(assert_invalid
   857  (module
   858    (global $x (mut i32) (i32.const 0))
   859    (func $type-condition-empty-in-global.set
   860      (global.set $x (if(then))) (global.get $x) (drop)
   861    )
   862  )
   863  "type mismatch"
   864)
   865(assert_invalid
   866  (module
   867    (memory 0)
   868    (func $type-condition-empty-in-memory.grow
   869      (memory.grow (if(then))) (drop)
   870    )
   871  )
   872  "type mismatch"
   873)
   874(assert_invalid
   875  (module
   876    (memory 0)
   877    (func $type-condition-empty-in-load
   878      (i32.load (if(then))) (drop)
   879    )
   880  )
   881  "type mismatch"
   882)
   883(assert_invalid
   884  (module
   885    (memory 1)
   886    (func $type-condition-empty-in-store
   887      (i32.store (if(then)) (i32.const 1))
   888    )
   889  )
   890  "type mismatch"
   891)
   892
   893
   894(assert_malformed
   895  (module quote "(func if end $l)")
   896  "mismatching label"
   897)
   898(assert_malformed
   899  (module quote "(func if $a end $l)")
   900  "mismatching label"
   901)
   902(assert_malformed
   903  (module quote "(func if else $l end)")
   904  "mismatching label"
   905)
   906(assert_malformed
   907  (module quote "(func if $a else $l end)")
   908  "mismatching label"
   909)
   910(assert_malformed
   911  (module quote "(func if else end $l)")
   912  "mismatching label"
   913)
   914(assert_malformed
   915  (module quote "(func if else $l end $l)")
   916  "mismatching label"
   917)
   918(assert_malformed
   919  (module quote "(func if else $l1 end $l2)")
   920  "mismatching label"
   921)
   922(assert_malformed
   923  (module quote "(func if $a else end $l)")
   924  "mismatching label"
   925)
   926(assert_malformed
   927  (module quote "(func if $a else $a end $l)")
   928  "mismatching label"
   929)
   930(assert_malformed
   931  (module quote "(func if $a else $l end $l)")
   932  "mismatching label"
   933)

View as plain text