wa-lang.org/wazero@v1.0.2/internal/integration_test/spectest/v2/testdata/if.wast (about)

     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 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) (call $dummy))
    27        (else (call $dummy) (call $dummy) (i32.const 9) (call $dummy))
    28      )
    29      (if (result i32 i64 i32) (local.get 0)
    30        (then
    31          (call $dummy) (call $dummy) (i32.const 1) (call $dummy)
    32          (call $dummy) (call $dummy) (i64.const 2) (call $dummy)
    33          (call $dummy) (call $dummy) (i32.const 3) (call $dummy)
    34        )
    35        (else
    36          (call $dummy) (call $dummy) (i32.const -1) (call $dummy)
    37          (call $dummy) (call $dummy) (i64.const -2) (call $dummy)
    38          (call $dummy) (call $dummy) (i32.const -3) (call $dummy)
    39        )
    40      )
    41      (drop) (drop)
    42    )
    43  
    44    (func (export "nested") (param i32 i32) (result i32)
    45      (if (result i32) (local.get 0)
    46        (then
    47          (if (local.get 1) (then (call $dummy) (block) (nop)))
    48          (if (local.get 1) (then) (else (call $dummy) (block) (nop)))
    49          (if (result i32) (local.get 1)
    50            (then (call $dummy) (i32.const 9))
    51            (else (call $dummy) (i32.const 10))
    52          )
    53        )
    54        (else
    55          (if (local.get 1) (then (call $dummy) (block) (nop)))
    56          (if (local.get 1) (then) (else (call $dummy) (block) (nop)))
    57          (if (result i32) (local.get 1)
    58            (then (call $dummy) (i32.const 10))
    59            (else (call $dummy) (i32.const 11))
    60          )
    61        )
    62      )
    63    )
    64  
    65    (func (export "as-select-first") (param i32) (result i32)
    66      (select
    67        (if (result i32) (local.get 0)
    68          (then (call $dummy) (i32.const 1))
    69          (else (call $dummy) (i32.const 0))
    70        )
    71        (i32.const 2) (i32.const 3)
    72      )
    73    )
    74    (func (export "as-select-mid") (param i32) (result i32)
    75      (select
    76        (i32.const 2)
    77        (if (result i32) (local.get 0)
    78          (then (call $dummy) (i32.const 1))
    79          (else (call $dummy) (i32.const 0))
    80        )
    81        (i32.const 3)
    82      )
    83    )
    84    (func (export "as-select-last") (param i32) (result i32)
    85      (select
    86        (i32.const 2) (i32.const 3)
    87        (if (result i32) (local.get 0)
    88          (then (call $dummy) (i32.const 1))
    89          (else (call $dummy) (i32.const 0))
    90        )
    91      )
    92    )
    93  
    94    (func (export "as-loop-first") (param i32) (result i32)
    95      (loop (result i32)
    96        (if (result i32) (local.get 0)
    97          (then (call $dummy) (i32.const 1))
    98          (else (call $dummy) (i32.const 0))
    99        )
   100        (call $dummy) (call $dummy)
   101      )
   102    )
   103    (func (export "as-loop-mid") (param i32) (result i32)
   104      (loop (result i32)
   105        (call $dummy)
   106        (if (result i32) (local.get 0)
   107          (then (call $dummy) (i32.const 1))
   108          (else (call $dummy) (i32.const 0))
   109        )
   110        (call $dummy)
   111      )
   112    )
   113    (func (export "as-loop-last") (param i32) (result i32)
   114      (loop (result i32)
   115        (call $dummy) (call $dummy)
   116        (if (result i32) (local.get 0)
   117          (then (call $dummy) (i32.const 1))
   118          (else (call $dummy) (i32.const 0))
   119        )
   120      )
   121    )
   122  
   123    (func (export "as-if-condition") (param i32) (result i32)
   124      (if (result i32)
   125        (if (result i32) (local.get 0)
   126          (then (i32.const 1)) (else (i32.const 0))
   127        )
   128        (then (call $dummy) (i32.const 2))
   129        (else (call $dummy) (i32.const 3))
   130      )
   131    )
   132  
   133    (func (export "as-br_if-first") (param i32) (result i32)
   134      (block (result i32)
   135        (br_if 0
   136          (if (result i32) (local.get 0)
   137            (then (call $dummy) (i32.const 1))
   138            (else (call $dummy) (i32.const 0))
   139          )
   140          (i32.const 2)
   141        )
   142        (return (i32.const 3))
   143      )
   144    )
   145    (func (export "as-br_if-last") (param i32) (result i32)
   146      (block (result i32)
   147        (br_if 0
   148          (i32.const 2)
   149          (if (result i32) (local.get 0)
   150            (then (call $dummy) (i32.const 1))
   151            (else (call $dummy) (i32.const 0))
   152          )
   153        )
   154        (return (i32.const 3))
   155      )
   156    )
   157  
   158    (func (export "as-br_table-first") (param i32) (result i32)
   159      (block (result i32)
   160        (if (result i32) (local.get 0)
   161          (then (call $dummy) (i32.const 1))
   162          (else (call $dummy) (i32.const 0))
   163        )
   164        (i32.const 2)
   165        (br_table 0 0)
   166      )
   167    )
   168    (func (export "as-br_table-last") (param i32) (result i32)
   169      (block (result i32)
   170        (i32.const 2)
   171        (if (result i32) (local.get 0)
   172          (then (call $dummy) (i32.const 1))
   173          (else (call $dummy) (i32.const 0))
   174        )
   175        (br_table 0 0)
   176      )
   177    )
   178  
   179    (func $func (param i32 i32) (result i32) (local.get 0))
   180    (type $check (func (param i32 i32) (result i32)))
   181    (table funcref (elem $func))
   182    (func (export "as-call_indirect-first") (param i32) (result i32)
   183      (block (result i32)
   184        (call_indirect (type $check)
   185          (if (result i32) (local.get 0)
   186            (then (call $dummy) (i32.const 1))
   187            (else (call $dummy) (i32.const 0))
   188          )
   189          (i32.const 2) (i32.const 0)
   190        )
   191      )
   192    )
   193    (func (export "as-call_indirect-mid") (param i32) (result i32)
   194      (block (result i32)
   195        (call_indirect (type $check)
   196          (i32.const 2)
   197          (if (result i32) (local.get 0)
   198            (then (call $dummy) (i32.const 1))
   199            (else (call $dummy) (i32.const 0))
   200          )
   201          (i32.const 0)
   202        )
   203      )
   204    )
   205    (func (export "as-call_indirect-last") (param i32) (result i32)
   206      (block (result i32)
   207        (call_indirect (type $check)
   208          (i32.const 2) (i32.const 0)
   209          (if (result i32) (local.get 0)
   210            (then (call $dummy) (i32.const 1))
   211            (else (call $dummy) (i32.const 0))
   212          )
   213        )
   214      )
   215    )
   216  
   217    (func (export "as-store-first") (param i32)
   218      (if (result i32) (local.get 0)
   219        (then (call $dummy) (i32.const 1))
   220        (else (call $dummy) (i32.const 0))
   221      )
   222      (i32.const 2)
   223      (i32.store)
   224    )
   225    (func (export "as-store-last") (param i32)
   226      (i32.const 2)
   227      (if (result i32) (local.get 0)
   228        (then (call $dummy) (i32.const 1))
   229        (else (call $dummy) (i32.const 0))
   230      )
   231      (i32.store)
   232    )
   233  
   234    (func (export "as-memory.grow-value") (param i32) (result i32)
   235      (memory.grow
   236        (if (result i32) (local.get 0)
   237          (then (i32.const 1))
   238          (else (i32.const 0))
   239        )
   240      )
   241    )
   242  
   243    (func $f (param i32) (result i32) (local.get 0))
   244  
   245    (func (export "as-call-value") (param i32) (result i32)
   246      (call $f
   247        (if (result i32) (local.get 0)
   248          (then (i32.const 1))
   249          (else (i32.const 0))
   250        )
   251      )
   252    )
   253    (func (export "as-return-value") (param i32) (result i32)
   254      (if (result i32) (local.get 0)
   255        (then (i32.const 1))
   256        (else (i32.const 0)))
   257      (return)
   258    )
   259    (func (export "as-drop-operand") (param i32)
   260      (drop
   261        (if (result i32) (local.get 0)
   262          (then (i32.const 1))
   263          (else (i32.const 0))
   264        )
   265      )
   266    )
   267    (func (export "as-br-value") (param i32) (result i32)
   268      (block (result i32)
   269        (br 0
   270          (if (result i32) (local.get 0)
   271            (then (i32.const 1))
   272            (else (i32.const 0))
   273          )
   274        )
   275      )
   276    )
   277    (func (export "as-local.set-value") (param i32) (result i32)
   278      (local i32)
   279      (local.set 0
   280        (if (result i32) (local.get 0)
   281          (then (i32.const 1))
   282          (else (i32.const 0))
   283        )
   284      )
   285      (local.get 0)
   286    )
   287    (func (export "as-local.tee-value") (param i32) (result i32)
   288      (local.tee 0
   289        (if (result i32) (local.get 0)
   290          (then (i32.const 1))
   291          (else (i32.const 0))
   292        )
   293      )
   294    )
   295    (global $a (mut i32) (i32.const 10))
   296    (func (export "as-global.set-value") (param i32) (result i32)
   297      (global.set $a
   298        (if (result i32) (local.get 0)
   299          (then (i32.const 1))
   300          (else (i32.const 0))
   301        )
   302      ) (global.get $a)
   303    )
   304    (func (export "as-load-operand") (param i32) (result i32)
   305      (i32.load
   306        (if (result i32) (local.get 0)
   307          (then (i32.const 11))
   308          (else (i32.const 10))
   309        )
   310      )
   311    )
   312  
   313    (func (export "as-unary-operand") (param i32) (result i32)
   314      (i32.ctz
   315        (if (result i32) (local.get 0)
   316          (then (call $dummy) (i32.const 13))
   317          (else (call $dummy) (i32.const -13))
   318        )
   319      )
   320    )
   321    (func (export "as-binary-operand") (param i32 i32) (result i32)
   322      (i32.mul
   323        (if (result i32) (local.get 0)
   324          (then (call $dummy) (i32.const 3))
   325          (else (call $dummy) (i32.const -3))
   326        )
   327        (if (result i32) (local.get 1)
   328          (then (call $dummy) (i32.const 4))
   329          (else (call $dummy) (i32.const -5))
   330        )
   331      )
   332    )
   333    (func (export "as-test-operand") (param i32) (result i32)
   334      (i32.eqz
   335        (if (result i32) (local.get 0)
   336          (then (call $dummy) (i32.const 13))
   337          (else (call $dummy) (i32.const 0))
   338        )
   339      )
   340    )
   341    (func (export "as-compare-operand") (param i32 i32) (result i32)
   342      (f32.gt
   343        (if (result f32) (local.get 0)
   344          (then (call $dummy) (f32.const 3))
   345          (else (call $dummy) (f32.const -3))
   346        )
   347        (if (result f32) (local.get 1)
   348          (then (call $dummy) (f32.const 4))
   349          (else (call $dummy) (f32.const -4))
   350        )
   351      )
   352    )
   353    (func (export "as-binary-operands") (param i32) (result i32)
   354      (i32.mul
   355        (if (result i32 i32) (local.get 0)
   356          (then (call $dummy) (i32.const 3) (call $dummy) (i32.const 4))
   357          (else (call $dummy) (i32.const 3) (call $dummy) (i32.const -4))
   358        )
   359      )
   360    )
   361    (func (export "as-compare-operands") (param i32) (result i32)
   362      (f32.gt
   363        (if (result f32 f32) (local.get 0)
   364          (then (call $dummy) (f32.const 3) (call $dummy) (f32.const 3))
   365          (else (call $dummy) (f32.const -2) (call $dummy) (f32.const -3))
   366        )
   367      )
   368    )
   369    (func (export "as-mixed-operands") (param i32) (result i32)
   370      (if (result i32 i32) (local.get 0)
   371        (then (call $dummy) (i32.const 3) (call $dummy) (i32.const 4))
   372        (else (call $dummy) (i32.const -3) (call $dummy) (i32.const -4))
   373      )
   374      (i32.const 5)
   375      (i32.add)
   376      (i32.mul)
   377    )
   378  
   379    (func (export "break-bare") (result i32)
   380      (if (i32.const 1) (then (br 0) (unreachable)))
   381      (if (i32.const 1) (then (br 0) (unreachable)) (else (unreachable)))
   382      (if (i32.const 0) (then (unreachable)) (else (br 0) (unreachable)))
   383      (if (i32.const 1) (then (br_if 0 (i32.const 1)) (unreachable)))
   384      (if (i32.const 1) (then (br_if 0 (i32.const 1)) (unreachable)) (else (unreachable)))
   385      (if (i32.const 0) (then (unreachable)) (else (br_if 0 (i32.const 1)) (unreachable)))
   386      (if (i32.const 1) (then (br_table 0 (i32.const 0)) (unreachable)))
   387      (if (i32.const 1) (then (br_table 0 (i32.const 0)) (unreachable)) (else (unreachable)))
   388      (if (i32.const 0) (then (unreachable)) (else (br_table 0 (i32.const 0)) (unreachable)))
   389      (i32.const 19)
   390    )
   391  
   392    (func (export "break-value") (param i32) (result i32)
   393      (if (result i32) (local.get 0)
   394        (then (br 0 (i32.const 18)) (i32.const 19))
   395        (else (br 0 (i32.const 21)) (i32.const 20))
   396      )
   397    )
   398    (func (export "break-multi-value") (param i32) (result i32 i32 i64)
   399      (if (result i32 i32 i64) (local.get 0)
   400        (then
   401          (br 0 (i32.const 18) (i32.const -18) (i64.const 18))
   402          (i32.const 19) (i32.const -19) (i64.const 19)
   403        )
   404        (else
   405          (br 0 (i32.const -18) (i32.const 18) (i64.const -18))
   406          (i32.const -19) (i32.const 19) (i64.const -19)
   407        )
   408      )
   409    )
   410  
   411    (func (export "param") (param i32) (result i32)
   412      (i32.const 1)
   413      (if (param i32) (result i32) (local.get 0)
   414        (then (i32.const 2) (i32.add))
   415        (else (i32.const -2) (i32.add))
   416      )
   417    )
   418    (func (export "params") (param i32) (result i32)
   419      (i32.const 1)
   420      (i32.const 2)
   421      (if (param i32 i32) (result i32) (local.get 0)
   422        (then (i32.add))
   423        (else (i32.sub))
   424      )
   425    )
   426    (func (export "params-id") (param i32) (result i32)
   427      (i32.const 1)
   428      (i32.const 2)
   429      (if (param i32 i32) (result i32 i32) (local.get 0) (then))
   430      (i32.add)
   431    )
   432    (func (export "param-break") (param i32) (result i32)
   433      (i32.const 1)
   434      (if (param i32) (result i32) (local.get 0)
   435        (then (i32.const 2) (i32.add) (br 0))
   436        (else (i32.const -2) (i32.add) (br 0))
   437      )
   438    )
   439    (func (export "params-break") (param i32) (result i32)
   440      (i32.const 1)
   441      (i32.const 2)
   442      (if (param i32 i32) (result i32) (local.get 0)
   443        (then (i32.add) (br 0))
   444        (else (i32.sub) (br 0))
   445      )
   446    )
   447    (func (export "params-id-break") (param i32) (result i32)
   448      (i32.const 1)
   449      (i32.const 2)
   450      (if (param i32 i32) (result i32 i32) (local.get 0) (then (br 0)))
   451      (i32.add)
   452    )
   453  
   454    (func (export "effects") (param i32) (result i32)
   455      (local i32)
   456      (if
   457        (block (result i32) (local.set 1 (i32.const 1)) (local.get 0))
   458        (then
   459          (local.set 1 (i32.mul (local.get 1) (i32.const 3)))
   460          (local.set 1 (i32.sub (local.get 1) (i32.const 5)))
   461          (local.set 1 (i32.mul (local.get 1) (i32.const 7)))
   462          (br 0)
   463          (local.set 1 (i32.mul (local.get 1) (i32.const 100)))
   464        )
   465        (else
   466          (local.set 1 (i32.mul (local.get 1) (i32.const 5)))
   467          (local.set 1 (i32.sub (local.get 1) (i32.const 7)))
   468          (local.set 1 (i32.mul (local.get 1) (i32.const 3)))
   469          (br 0)
   470          (local.set 1 (i32.mul (local.get 1) (i32.const 1000)))
   471        )
   472      )
   473      (local.get 1)
   474    )
   475  
   476    ;; Examples
   477  
   478    (func $add64_u_with_carry (export "add64_u_with_carry")
   479      (param $i i64) (param $j i64) (param $c i32) (result i64 i32)
   480      (local $k i64)
   481      (local.set $k
   482        (i64.add
   483          (i64.add (local.get $i) (local.get $j))
   484          (i64.extend_i32_u (local.get $c))
   485        )
   486      )
   487      (return (local.get $k) (i64.lt_u (local.get $k) (local.get $i)))
   488    )
   489  
   490    (func $add64_u_saturated (export "add64_u_saturated")
   491      (param i64 i64) (result i64)
   492      (call $add64_u_with_carry (local.get 0) (local.get 1) (i32.const 0))
   493      (if (param i64) (result i64)
   494        (then (drop) (i64.const -1))
   495      )
   496    )
   497  
   498    ;; Block signature syntax
   499  
   500    (type $block-sig-1 (func))
   501    (type $block-sig-2 (func (result i32)))
   502    (type $block-sig-3 (func (param $x i32)))
   503    (type $block-sig-4 (func (param i32 f64 i32) (result i32 f64 i32)))
   504  
   505    (func (export "type-use")
   506      (if (type $block-sig-1) (i32.const 1) (then))
   507      (if (type $block-sig-2) (i32.const 1)
   508        (then (i32.const 0)) (else (i32.const 2))
   509      )
   510      (if (type $block-sig-3) (i32.const 1) (then (drop)) (else (drop)))
   511      (i32.const 0) (f64.const 0) (i32.const 0)
   512      (if (type $block-sig-4) (i32.const 1) (then))
   513      (drop) (drop) (drop)
   514      (if (type $block-sig-2) (result i32) (i32.const 1)
   515        (then (i32.const 0)) (else (i32.const 2))
   516      )
   517      (if (type $block-sig-3) (param i32) (i32.const 1)
   518        (then (drop)) (else (drop))
   519      )
   520      (i32.const 0) (f64.const 0) (i32.const 0)
   521      (if (type $block-sig-4)
   522        (param i32) (param f64 i32) (result i32 f64) (result i32)
   523        (i32.const 1) (then)
   524      )
   525      (drop) (drop) (drop)
   526    )
   527  )
   528  
   529  (assert_return (invoke "empty" (i32.const 0)))
   530  (assert_return (invoke "empty" (i32.const 1)))
   531  (assert_return (invoke "empty" (i32.const 100)))
   532  (assert_return (invoke "empty" (i32.const -2)))
   533  
   534  (assert_return (invoke "singular" (i32.const 0)) (i32.const 8))
   535  (assert_return (invoke "singular" (i32.const 1)) (i32.const 7))
   536  (assert_return (invoke "singular" (i32.const 10)) (i32.const 7))
   537  (assert_return (invoke "singular" (i32.const -10)) (i32.const 7))
   538  
   539  (assert_return (invoke "multi" (i32.const 0)) (i32.const 9) (i32.const -1))
   540  (assert_return (invoke "multi" (i32.const 1)) (i32.const 8) (i32.const 1))
   541  (assert_return (invoke "multi" (i32.const 13)) (i32.const 8) (i32.const 1))
   542  (assert_return (invoke "multi" (i32.const -5)) (i32.const 8) (i32.const 1))
   543  
   544  (assert_return (invoke "nested" (i32.const 0) (i32.const 0)) (i32.const 11))
   545  (assert_return (invoke "nested" (i32.const 1) (i32.const 0)) (i32.const 10))
   546  (assert_return (invoke "nested" (i32.const 0) (i32.const 1)) (i32.const 10))
   547  (assert_return (invoke "nested" (i32.const 3) (i32.const 2)) (i32.const 9))
   548  (assert_return (invoke "nested" (i32.const 0) (i32.const -100)) (i32.const 10))
   549  (assert_return (invoke "nested" (i32.const 10) (i32.const 10)) (i32.const 9))
   550  (assert_return (invoke "nested" (i32.const 0) (i32.const -1)) (i32.const 10))
   551  (assert_return (invoke "nested" (i32.const -111) (i32.const -2)) (i32.const 9))
   552  
   553  (assert_return (invoke "as-select-first" (i32.const 0)) (i32.const 0))
   554  (assert_return (invoke "as-select-first" (i32.const 1)) (i32.const 1))
   555  (assert_return (invoke "as-select-mid" (i32.const 0)) (i32.const 2))
   556  (assert_return (invoke "as-select-mid" (i32.const 1)) (i32.const 2))
   557  (assert_return (invoke "as-select-last" (i32.const 0)) (i32.const 3))
   558  (assert_return (invoke "as-select-last" (i32.const 1)) (i32.const 2))
   559  
   560  (assert_return (invoke "as-loop-first" (i32.const 0)) (i32.const 0))
   561  (assert_return (invoke "as-loop-first" (i32.const 1)) (i32.const 1))
   562  (assert_return (invoke "as-loop-mid" (i32.const 0)) (i32.const 0))
   563  (assert_return (invoke "as-loop-mid" (i32.const 1)) (i32.const 1))
   564  (assert_return (invoke "as-loop-last" (i32.const 0)) (i32.const 0))
   565  (assert_return (invoke "as-loop-last" (i32.const 1)) (i32.const 1))
   566  
   567  (assert_return (invoke "as-if-condition" (i32.const 0)) (i32.const 3))
   568  (assert_return (invoke "as-if-condition" (i32.const 1)) (i32.const 2))
   569  
   570  (assert_return (invoke "as-br_if-first" (i32.const 0)) (i32.const 0))
   571  (assert_return (invoke "as-br_if-first" (i32.const 1)) (i32.const 1))
   572  (assert_return (invoke "as-br_if-last" (i32.const 0)) (i32.const 3))
   573  (assert_return (invoke "as-br_if-last" (i32.const 1)) (i32.const 2))
   574  
   575  (assert_return (invoke "as-br_table-first" (i32.const 0)) (i32.const 0))
   576  (assert_return (invoke "as-br_table-first" (i32.const 1)) (i32.const 1))
   577  (assert_return (invoke "as-br_table-last" (i32.const 0)) (i32.const 2))
   578  (assert_return (invoke "as-br_table-last" (i32.const 1)) (i32.const 2))
   579  
   580  (assert_return (invoke "as-call_indirect-first" (i32.const 0)) (i32.const 0))
   581  (assert_return (invoke "as-call_indirect-first" (i32.const 1)) (i32.const 1))
   582  (assert_return (invoke "as-call_indirect-mid" (i32.const 0)) (i32.const 2))
   583  (assert_return (invoke "as-call_indirect-mid" (i32.const 1)) (i32.const 2))
   584  (assert_return (invoke "as-call_indirect-last" (i32.const 0)) (i32.const 2))
   585  (assert_trap (invoke "as-call_indirect-last" (i32.const 1)) "undefined element")
   586  
   587  (assert_return (invoke "as-store-first" (i32.const 0)))
   588  (assert_return (invoke "as-store-first" (i32.const 1)))
   589  (assert_return (invoke "as-store-last" (i32.const 0)))
   590  (assert_return (invoke "as-store-last" (i32.const 1)))
   591  
   592  (assert_return (invoke "as-memory.grow-value" (i32.const 0)) (i32.const 1))
   593  (assert_return (invoke "as-memory.grow-value" (i32.const 1)) (i32.const 1))
   594  
   595  (assert_return (invoke "as-call-value" (i32.const 0)) (i32.const 0))
   596  (assert_return (invoke "as-call-value" (i32.const 1)) (i32.const 1))
   597  
   598  (assert_return (invoke "as-return-value" (i32.const 0)) (i32.const 0))
   599  (assert_return (invoke "as-return-value" (i32.const 1)) (i32.const 1))
   600  
   601  (assert_return (invoke "as-drop-operand" (i32.const 0)))
   602  (assert_return (invoke "as-drop-operand" (i32.const 1)))
   603  
   604  (assert_return (invoke "as-br-value" (i32.const 0)) (i32.const 0))
   605  (assert_return (invoke "as-br-value" (i32.const 1)) (i32.const 1))
   606  
   607  (assert_return (invoke "as-local.set-value" (i32.const 0)) (i32.const 0))
   608  (assert_return (invoke "as-local.set-value" (i32.const 1)) (i32.const 1))
   609  
   610  (assert_return (invoke "as-local.tee-value" (i32.const 0)) (i32.const 0))
   611  (assert_return (invoke "as-local.tee-value" (i32.const 1)) (i32.const 1))
   612  
   613  (assert_return (invoke "as-global.set-value" (i32.const 0)) (i32.const 0))
   614  (assert_return (invoke "as-global.set-value" (i32.const 1)) (i32.const 1))
   615  
   616  (assert_return (invoke "as-load-operand" (i32.const 0)) (i32.const 0))
   617  (assert_return (invoke "as-load-operand" (i32.const 1)) (i32.const 0))
   618  
   619  (assert_return (invoke "as-unary-operand" (i32.const 0)) (i32.const 0))
   620  (assert_return (invoke "as-unary-operand" (i32.const 1)) (i32.const 0))
   621  (assert_return (invoke "as-unary-operand" (i32.const -1)) (i32.const 0))
   622  
   623  (assert_return (invoke "as-binary-operand" (i32.const 0) (i32.const 0)) (i32.const 15))
   624  (assert_return (invoke "as-binary-operand" (i32.const 0) (i32.const 1)) (i32.const -12))
   625  (assert_return (invoke "as-binary-operand" (i32.const 1) (i32.const 0)) (i32.const -15))
   626  (assert_return (invoke "as-binary-operand" (i32.const 1) (i32.const 1)) (i32.const 12))
   627  
   628  (assert_return (invoke "as-test-operand" (i32.const 0)) (i32.const 1))
   629  (assert_return (invoke "as-test-operand" (i32.const 1)) (i32.const 0))
   630  
   631  (assert_return (invoke "as-compare-operand" (i32.const 0) (i32.const 0)) (i32.const 1))
   632  (assert_return (invoke "as-compare-operand" (i32.const 0) (i32.const 1)) (i32.const 0))
   633  (assert_return (invoke "as-compare-operand" (i32.const 1) (i32.const 0)) (i32.const 1))
   634  (assert_return (invoke "as-compare-operand" (i32.const 1) (i32.const 1)) (i32.const 0))
   635  
   636  (assert_return (invoke "as-binary-operands" (i32.const 0)) (i32.const -12))
   637  (assert_return (invoke "as-binary-operands" (i32.const 1)) (i32.const 12))
   638  
   639  (assert_return (invoke "as-compare-operands" (i32.const 0)) (i32.const 1))
   640  (assert_return (invoke "as-compare-operands" (i32.const 1)) (i32.const 0))
   641  
   642  (assert_return (invoke "as-mixed-operands" (i32.const 0)) (i32.const -3))
   643  (assert_return (invoke "as-mixed-operands" (i32.const 1)) (i32.const 27))
   644  
   645  (assert_return (invoke "break-bare") (i32.const 19))
   646  (assert_return (invoke "break-value" (i32.const 1)) (i32.const 18))
   647  (assert_return (invoke "break-value" (i32.const 0)) (i32.const 21))
   648  (assert_return (invoke "break-multi-value" (i32.const 0))
   649    (i32.const -18) (i32.const 18) (i64.const -18)
   650  )
   651  (assert_return (invoke "break-multi-value" (i32.const 1))
   652    (i32.const 18) (i32.const -18) (i64.const 18)
   653  )
   654  
   655  (assert_return (invoke "param" (i32.const 0)) (i32.const -1))
   656  (assert_return (invoke "param" (i32.const 1)) (i32.const 3))
   657  (assert_return (invoke "params" (i32.const 0)) (i32.const -1))
   658  (assert_return (invoke "params" (i32.const 1)) (i32.const 3))
   659  (assert_return (invoke "params-id" (i32.const 0)) (i32.const 3))
   660  (assert_return (invoke "params-id" (i32.const 1)) (i32.const 3))
   661  (assert_return (invoke "param-break" (i32.const 0)) (i32.const -1))
   662  (assert_return (invoke "param-break" (i32.const 1)) (i32.const 3))
   663  (assert_return (invoke "params-break" (i32.const 0)) (i32.const -1))
   664  (assert_return (invoke "params-break" (i32.const 1)) (i32.const 3))
   665  (assert_return (invoke "params-id-break" (i32.const 0)) (i32.const 3))
   666  (assert_return (invoke "params-id-break" (i32.const 1)) (i32.const 3))
   667  
   668  (assert_return (invoke "effects" (i32.const 1)) (i32.const -14))
   669  (assert_return (invoke "effects" (i32.const 0)) (i32.const -6))
   670  
   671  (assert_return
   672    (invoke "add64_u_with_carry" (i64.const 0) (i64.const 0) (i32.const 0))
   673    (i64.const 0) (i32.const 0)
   674  )
   675  (assert_return
   676    (invoke "add64_u_with_carry" (i64.const 100) (i64.const 124) (i32.const 0))
   677    (i64.const 224) (i32.const 0)
   678  )
   679  (assert_return
   680    (invoke "add64_u_with_carry" (i64.const -1) (i64.const 0) (i32.const 0))
   681    (i64.const -1) (i32.const 0)
   682  )
   683  (assert_return
   684    (invoke "add64_u_with_carry" (i64.const -1) (i64.const 1) (i32.const 0))
   685    (i64.const 0) (i32.const 1)
   686  )
   687  (assert_return
   688    (invoke "add64_u_with_carry" (i64.const -1) (i64.const -1) (i32.const 0))
   689    (i64.const -2) (i32.const 1)
   690  )
   691  (assert_return
   692    (invoke "add64_u_with_carry" (i64.const -1) (i64.const 0) (i32.const 1))
   693    (i64.const 0) (i32.const 1)
   694  )
   695  (assert_return
   696    (invoke "add64_u_with_carry" (i64.const -1) (i64.const 1) (i32.const 1))
   697    (i64.const 1) (i32.const 1)
   698  )
   699  (assert_return
   700    (invoke "add64_u_with_carry" (i64.const 0x8000000000000000) (i64.const 0x8000000000000000) (i32.const 0))
   701    (i64.const 0) (i32.const 1)
   702  )
   703  
   704  (assert_return
   705    (invoke "add64_u_saturated" (i64.const 0) (i64.const 0)) (i64.const 0)
   706  )
   707  (assert_return
   708    (invoke "add64_u_saturated" (i64.const 1230) (i64.const 23)) (i64.const 1253)
   709  )
   710  (assert_return
   711    (invoke "add64_u_saturated" (i64.const -1) (i64.const 0)) (i64.const -1)
   712  )
   713  (assert_return
   714    (invoke "add64_u_saturated" (i64.const -1) (i64.const 1)) (i64.const -1)
   715  )
   716  (assert_return
   717    (invoke "add64_u_saturated" (i64.const -1) (i64.const -1)) (i64.const -1)
   718  )
   719  (assert_return
   720    (invoke "add64_u_saturated" (i64.const 0x8000000000000000) (i64.const 0x8000000000000000)) (i64.const -1)
   721  )
   722  
   723  (assert_return (invoke "type-use"))
   724  
   725  (assert_malformed
   726    (module quote
   727      "(type $sig (func (param i32) (result i32)))"
   728      "(func (i32.const 0)"
   729      "  (if (type $sig) (result i32) (param i32) (i32.const 1) (then))"
   730      ")"
   731    )
   732    "unexpected token"
   733  )
   734  (assert_malformed
   735    (module quote
   736      "(type $sig (func (param i32) (result i32)))"
   737      "(func (i32.const 0)"
   738      "  (if (param i32) (type $sig) (result i32) (i32.const 1) (then))"
   739      ")"
   740    )
   741    "unexpected token"
   742  )
   743  (assert_malformed
   744    (module quote
   745      "(type $sig (func (param i32) (result i32)))"
   746      "(func (i32.const 0)"
   747      "  (if (param i32) (result i32) (type $sig) (i32.const 1) (then))"
   748      ")"
   749    )
   750    "unexpected token"
   751  )
   752  (assert_malformed
   753    (module quote
   754      "(type $sig (func (param i32) (result i32)))"
   755      "(func (i32.const 0)"
   756      "  (if (result i32) (type $sig) (param i32) (i32.const 1) (then))"
   757      ")"
   758    )
   759    "unexpected token"
   760  )
   761  (assert_malformed
   762    (module quote
   763      "(type $sig (func (param i32) (result i32)))"
   764      "(func (i32.const 0)"
   765      "  (if (result i32) (param i32) (type $sig) (i32.const 1) (then))"
   766      ")"
   767    )
   768    "unexpected token"
   769  )
   770  (assert_malformed
   771    (module quote
   772      "(func (i32.const 0) (if (result i32) (param i32) (i32.const 1) (then)))"
   773    )
   774    "unexpected token"
   775  )
   776  
   777  (assert_malformed
   778    (module quote
   779      "(func (i32.const 0) (i32.const 1)"
   780      "  (if (param $x i32) (then (drop)) (else (drop)))"
   781      ")"
   782    )
   783    "unexpected token"
   784  )
   785  (assert_malformed
   786    (module quote
   787      "(type $sig (func))"
   788      "(func (i32.const 1)"
   789      "  (if (type $sig) (result i32) (then (i32.const 0)) (else (i32.const 2)))"
   790      "  (unreachable)"
   791      ")"
   792    )
   793    "inline function type"
   794  )
   795  (assert_malformed
   796    (module quote
   797      "(type $sig (func (param i32) (result i32)))"
   798      "(func (i32.const 1)"
   799      "  (if (type $sig) (result i32) (then (i32.const 0)) (else (i32.const 2)))"
   800      "  (unreachable)"
   801      ")"
   802    )
   803    "inline function type"
   804  )
   805  (assert_malformed
   806    (module quote
   807      "(type $sig (func (param i32) (result i32)))"
   808      "(func (i32.const 0) (i32.const 1)"
   809      "  (if (type $sig) (param i32) (then (drop)) (else (drop)))"
   810      "  (unreachable)"
   811      ")"
   812    )
   813    "inline function type"
   814  )
   815  (assert_malformed
   816    (module quote
   817      "(type $sig (func (param i32 i32) (result i32)))"
   818      "(func (i32.const 0) (i32.const 1)"
   819      "  (if (type $sig) (param i32) (result i32) (then)) (unreachable)"
   820      ")"
   821    )
   822    "inline function type"
   823  )
   824  
   825  (assert_invalid
   826    (module
   827      (type $sig (func))
   828      (func (i32.const 1) (if (type $sig) (i32.const 0) (then)))
   829    )
   830    "type mismatch"
   831  )
   832  
   833  (assert_invalid
   834    (module (func $type-empty-i32 (result i32) (if (i32.const 0) (then))))
   835    "type mismatch"
   836  )
   837  (assert_invalid
   838    (module (func $type-empty-i64 (result i64) (if (i32.const 0) (then))))
   839    "type mismatch"
   840  )
   841  (assert_invalid
   842    (module (func $type-empty-f32 (result f32) (if (i32.const 0) (then))))
   843    "type mismatch"
   844  )
   845  (assert_invalid
   846    (module (func $type-empty-f64 (result f64) (if (i32.const 0) (then))))
   847    "type mismatch"
   848  )
   849  
   850  (assert_invalid
   851    (module (func $type-empty-i32 (result i32) (if (i32.const 0) (then) (else))))
   852    "type mismatch"
   853  )
   854  (assert_invalid
   855    (module (func $type-empty-i64 (result i64) (if (i32.const 0) (then) (else))))
   856    "type mismatch"
   857  )
   858  (assert_invalid
   859    (module (func $type-empty-f32 (result f32) (if (i32.const 0) (then) (else))))
   860    "type mismatch"
   861  )
   862  (assert_invalid
   863    (module (func $type-empty-f64 (result f64) (if (i32.const 0) (then) (else))))
   864    "type mismatch"
   865  )
   866  
   867  (assert_invalid
   868    (module (func $type-then-value-num-vs-void
   869      (if (i32.const 1) (then (i32.const 1)))
   870    ))
   871    "type mismatch"
   872  )
   873  (assert_invalid
   874    (module (func $type-then-value-num-vs-void-else
   875      (if (i32.const 1) (then (i32.const 1)) (else))
   876    ))
   877    "type mismatch"
   878  )
   879  (assert_invalid
   880    (module (func $type-else-value-num-vs-void
   881      (if (i32.const 1) (then) (else (i32.const 1)))
   882    ))
   883    "type mismatch"
   884  )
   885  (assert_invalid
   886    (module (func $type-both-value-num-vs-void
   887      (if (i32.const 1) (then (i32.const 1)) (else (i32.const 1)))
   888    ))
   889    "type mismatch"
   890  )
   891  
   892  (assert_invalid
   893    (module (func $type-then-value-nums-vs-void
   894      (if (i32.const 1) (then (i32.const 1) (i32.const 2)))
   895    ))
   896    "type mismatch"
   897  )
   898  (assert_invalid
   899    (module (func $type-then-value-nums-vs-void-else
   900      (if (i32.const 1) (then (i32.const 1) (i32.const 2)) (else))
   901    ))
   902    "type mismatch"
   903  )
   904  (assert_invalid
   905    (module (func $type-else-value-nums-vs-void
   906      (if (i32.const 1) (then) (else (i32.const 1) (i32.const 2)))
   907    ))
   908    "type mismatch"
   909  )
   910  (assert_invalid
   911    (module (func $type-both-value-nums-vs-void
   912      (if (i32.const 1) (then (i32.const 1) (i32.const 2)) (else (i32.const 2) (i32.const 1)))
   913    ))
   914    "type mismatch"
   915  )
   916  
   917  (assert_invalid
   918    (module (func $type-then-value-empty-vs-num (result i32)
   919      (if (result i32) (i32.const 1) (then) (else (i32.const 0)))
   920    ))
   921    "type mismatch"
   922  )
   923  (assert_invalid
   924    (module (func $type-else-value-empty-vs-num (result i32)
   925      (if (result i32) (i32.const 1) (then (i32.const 0)) (else))
   926    ))
   927    "type mismatch"
   928  )
   929  (assert_invalid
   930    (module (func $type-both-value-empty-vs-num (result i32)
   931      (if (result i32) (i32.const 1) (then) (else))
   932    ))
   933    "type mismatch"
   934  )
   935  
   936  (assert_invalid
   937    (module (func $type-then-value-empty-vs-nums (result i32 i32)
   938      (if (result i32 i32) (i32.const 1) (then) (else (i32.const 0) (i32.const 2)))
   939    ))
   940    "type mismatch"
   941  )
   942  (assert_invalid
   943    (module (func $type-else-value-empty-vs-nums (result i32 i32)
   944      (if (result i32 i32) (i32.const 1) (then (i32.const 0) (i32.const 1)) (else))
   945    ))
   946    "type mismatch"
   947  )
   948  (assert_invalid
   949    (module (func $type-both-value-empty-vs-nums (result i32 i32)
   950      (if (result i32 i32) (i32.const 1) (then) (else))
   951    ))
   952    "type mismatch"
   953  )
   954  
   955  (assert_invalid
   956    (module (func $type-no-else-vs-num (result i32)
   957      (if (result i32) (i32.const 1) (then (i32.const 1)))
   958    ))
   959    "type mismatch"
   960  )
   961  (assert_invalid
   962    (module (func $type-no-else-vs-nums (result i32 i32)
   963      (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1)))
   964    ))
   965    "type mismatch"
   966  )
   967  
   968  (assert_invalid
   969    (module (func $type-then-value-void-vs-num (result i32)
   970      (if (result i32) (i32.const 1) (then (nop)) (else (i32.const 0)))
   971    ))
   972    "type mismatch"
   973  )
   974  (assert_invalid
   975    (module (func $type-else-value-void-vs-num (result i32)
   976      (if (result i32) (i32.const 1) (then (i32.const 0)) (else (nop)))
   977    ))
   978    "type mismatch"
   979  )
   980  (assert_invalid
   981    (module (func $type-both-value-void-vs-num (result i32)
   982      (if (result i32) (i32.const 1) (then (nop)) (else (nop)))
   983    ))
   984    "type mismatch"
   985  )
   986  
   987  (assert_invalid
   988    (module (func $type-then-value-void-vs-nums (result i32 i32)
   989      (if (result i32 i32) (i32.const 1) (then (nop)) (else (i32.const 0) (i32.const 0)))
   990    ))
   991    "type mismatch"
   992  )
   993  (assert_invalid
   994    (module (func $type-else-value-void-vs-nums (result i32 i32)
   995      (if (result i32 i32) (i32.const 1) (then (i32.const 0) (i32.const 0)) (else (nop)))
   996    ))
   997    "type mismatch"
   998  )
   999  (assert_invalid
  1000    (module (func $type-both-value-void-vs-nums (result i32 i32)
  1001      (if (result i32 i32) (i32.const 1) (then (nop)) (else (nop)))
  1002    ))
  1003    "type mismatch"
  1004  )
  1005  
  1006  (assert_invalid
  1007    (module (func $type-then-value-num-vs-num (result i32)
  1008      (if (result i32) (i32.const 1) (then (i64.const 1)) (else (i32.const 1)))
  1009    ))
  1010    "type mismatch"
  1011  )
  1012  (assert_invalid
  1013    (module (func $type-else-value-num-vs-num (result i32)
  1014      (if (result i32) (i32.const 1) (then (i32.const 1)) (else (i64.const 1)))
  1015    ))
  1016    "type mismatch"
  1017  )
  1018  (assert_invalid
  1019    (module (func $type-both-value-num-vs-num (result i32)
  1020      (if (result i32) (i32.const 1) (then (i64.const 1)) (else (i64.const 1)))
  1021    ))
  1022    "type mismatch"
  1023  )
  1024  
  1025  (assert_invalid
  1026    (module (func $type-then-value-num-vs-nums (result i32 i32)
  1027      (if (result i32 i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1) (i32.const 1)))
  1028    ))
  1029    "type mismatch"
  1030  )
  1031  (assert_invalid
  1032    (module (func $type-else-value-num-vs-nums (result i32 i32)
  1033      (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (i32.const 1)))
  1034    ))
  1035    "type mismatch"
  1036  )
  1037  (assert_invalid
  1038    (module (func $type-both-value-num-vs-nums (result i32 i32)
  1039      (if (result i32 i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1)))
  1040    ))
  1041    "type mismatch"
  1042  )
  1043  
  1044  (assert_invalid
  1045    (module (func $type-then-value-partial-vs-nums (result i32 i32)
  1046      (i32.const 0)
  1047      (if (result i32 i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1) (i32.const 1)))
  1048    ))
  1049    "type mismatch"
  1050  )
  1051  (assert_invalid
  1052    (module (func $type-else-value-partial-vs-nums (result i32 i32)
  1053      (i32.const 0)
  1054      (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (i32.const 1)))
  1055    ))
  1056    "type mismatch"
  1057  )
  1058  (assert_invalid
  1059    (module (func $type-both-value-partial-vs-nums (result i32 i32)
  1060      (i32.const 0)
  1061      (if (result i32 i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1)))
  1062    ))
  1063    "type mismatch"
  1064  )
  1065  
  1066  (assert_invalid
  1067    (module (func $type-then-value-nums-vs-num (result i32)
  1068      (if (result i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (i32.const 1)))
  1069    ))
  1070    "type mismatch"
  1071  )
  1072  (assert_invalid
  1073    (module (func $type-else-value-nums-vs-num (result i32)
  1074      (if (result i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1) (i32.const 1)))
  1075    ))
  1076    "type mismatch"
  1077  )
  1078  (assert_invalid
  1079    (module (func $type-both-value-nums-vs-num (result i32)
  1080      (if (result i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (i32.const 1) (i32.const 1)))
  1081    ))
  1082    "type mismatch"
  1083  )
  1084  
  1085  (assert_invalid
  1086    (module (func $type-both-different-value-num-vs-num (result i32)
  1087      (if (result i32) (i32.const 1) (then (i64.const 1)) (else (f64.const 1)))
  1088    ))
  1089    "type mismatch"
  1090  )
  1091  (assert_invalid
  1092    (module (func $type-both-different-value-nums-vs-nums (result i32 i32)
  1093      (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1) (i32.const 1)) (else (i32.const 1)))
  1094    ))
  1095    "type mismatch"
  1096  )
  1097  
  1098  (assert_invalid
  1099    (module (func $type-then-value-unreached-select (result i32)
  1100      (if (result i64)
  1101        (i32.const 0)
  1102        (then (select (unreachable) (unreachable) (unreachable)))
  1103        (else (i64.const 0))
  1104      )
  1105    ))
  1106    "type mismatch"
  1107  )
  1108  (assert_invalid
  1109    (module (func $type-else-value-unreached-select (result i32)
  1110      (if (result i64)
  1111        (i32.const 1)
  1112        (then (i64.const 0))
  1113        (else (select (unreachable) (unreachable) (unreachable)))
  1114      )
  1115    ))
  1116    "type mismatch"
  1117  )
  1118  (assert_invalid
  1119    (module (func $type-else-value-unreached-select (result i32)
  1120      (if (result i64)
  1121        (i32.const 1)
  1122        (then (select (unreachable) (unreachable) (unreachable)))
  1123        (else (select (unreachable) (unreachable) (unreachable)))
  1124      )
  1125    ))
  1126    "type mismatch"
  1127  )
  1128  
  1129  (assert_invalid
  1130    (module (func $type-then-break-last-void-vs-num (result i32)
  1131      (if (result i32) (i32.const 1) (then (br 0)) (else (i32.const 1)))
  1132    ))
  1133    "type mismatch"
  1134  )
  1135  (assert_invalid
  1136    (module (func $type-else-break-last-void-vs-num (result i32)
  1137      (if (result i32) (i32.const 1) (then (i32.const 1)) (else (br 0)))
  1138    ))
  1139    "type mismatch"
  1140  )
  1141  (assert_invalid
  1142    (module (func $type-then-break-last-void-vs-nums (result i32 i32)
  1143      (if (result i32 i32) (i32.const 1) (then (br 0)) (else (i32.const 1) (i32.const 1)))
  1144    ))
  1145    "type mismatch"
  1146  )
  1147  (assert_invalid
  1148    (module (func $type-else-break-last-void-vs-nums (result i32 i32)
  1149      (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (br 0)))
  1150    ))
  1151    "type mismatch"
  1152  )
  1153  
  1154  (assert_invalid
  1155    (module (func $type-then-break-empty-vs-num (result i32)
  1156      (if (result i32) (i32.const 1)
  1157        (then (br 0) (i32.const 1))
  1158        (else (i32.const 1))
  1159      )
  1160    ))
  1161    "type mismatch"
  1162  )
  1163  (assert_invalid
  1164    (module (func $type-else-break-empty-vs-num (result i32)
  1165      (if (result i32) (i32.const 1)
  1166        (then (i32.const 1))
  1167        (else (br 0) (i32.const 1))
  1168      )
  1169    ))
  1170    "type mismatch"
  1171  )
  1172  (assert_invalid
  1173    (module (func $type-then-break-empty-vs-nums (result i32 i32)
  1174      (if (result i32 i32) (i32.const 1)
  1175        (then (br 0) (i32.const 1) (i32.const 1))
  1176        (else (i32.const 1) (i32.const 1))
  1177      )
  1178    ))
  1179    "type mismatch"
  1180  )
  1181  (assert_invalid
  1182    (module (func $type-else-break-empty-vs-nums (result i32 i32)
  1183      (if (result i32 i32) (i32.const 1)
  1184        (then (i32.const 1) (i32.const 1))
  1185        (else (br 0) (i32.const 1) (i32.const 1))
  1186      )
  1187    ))
  1188    "type mismatch"
  1189  )
  1190  
  1191  (assert_invalid
  1192    (module (func $type-then-break-void-vs-num (result i32)
  1193      (if (result i32) (i32.const 1)
  1194        (then (br 0 (nop)) (i32.const 1))
  1195        (else (i32.const 1))
  1196      )
  1197    ))
  1198    "type mismatch"
  1199  )
  1200  (assert_invalid
  1201    (module (func $type-else-break-void-vs-num (result i32)
  1202      (if (result i32) (i32.const 1)
  1203        (then (i32.const 1))
  1204        (else (br 0 (nop)) (i32.const 1))
  1205      )
  1206    ))
  1207    "type mismatch"
  1208  )
  1209  (assert_invalid
  1210    (module (func $type-then-break-void-vs-nums (result i32 i32)
  1211      (if (result i32 i32) (i32.const 1)
  1212        (then (br 0 (nop)) (i32.const 1) (i32.const 1))
  1213        (else (i32.const 1) (i32.const 1))
  1214      )
  1215    ))
  1216    "type mismatch"
  1217  )
  1218  (assert_invalid
  1219    (module (func $type-else-break-void-vs-nums (result i32 i32)
  1220      (if (result i32 i32) (i32.const 1)
  1221        (then (i32.const 1) (i32.const 1))
  1222        (else (br 0 (nop)) (i32.const 1) (i32.const 1))
  1223      )
  1224    ))
  1225    "type mismatch"
  1226  )
  1227  
  1228  (assert_invalid
  1229    (module (func $type-then-break-num-vs-num (result i32)
  1230      (if (result i32) (i32.const 1)
  1231        (then (br 0 (i64.const 1)) (i32.const 1))
  1232        (else (i32.const 1))
  1233      )
  1234    ))
  1235    "type mismatch"
  1236  )
  1237  (assert_invalid
  1238    (module (func $type-else-break-num-vs-num (result i32)
  1239      (if (result i32) (i32.const 1)
  1240        (then (i32.const 1))
  1241        (else (br 0 (i64.const 1)) (i32.const 1))
  1242      )
  1243    ))
  1244    "type mismatch"
  1245  )
  1246  (assert_invalid
  1247    (module (func $type-then-break-num-vs-nums (result i32 i32)
  1248      (if (result i32 i32) (i32.const 1)
  1249        (then (br 0 (i64.const 1)) (i32.const 1) (i32.const 1))
  1250        (else (i32.const 1) (i32.const 1))
  1251      )
  1252    ))
  1253    "type mismatch"
  1254  )
  1255  (assert_invalid
  1256    (module (func $type-else-break-num-vs-nums (result i32 i32)
  1257      (if (result i32 i32) (i32.const 1)
  1258        (then (i32.const 1) (i32.const 1))
  1259        (else (br 0 (i64.const 1)) (i32.const 1) (i32.const 1))
  1260      )
  1261    ))
  1262    "type mismatch"
  1263  )
  1264  (assert_invalid
  1265    (module (func $type-then-break-partial-vs-nums (result i32 i32)
  1266      (i32.const 1)
  1267      (if (result i32 i32) (i32.const 1)
  1268        (then (br 0 (i64.const 1)) (i32.const 1))
  1269        (else (i32.const 1))
  1270      )
  1271    ))
  1272    "type mismatch"
  1273  )
  1274  (assert_invalid
  1275    (module (func $type-else-break-partial-vs-nums (result i32 i32)
  1276      (i32.const 1)
  1277      (if (result i32 i32) (i32.const 1)
  1278        (then (i32.const 1))
  1279        (else (br 0 (i64.const 1)) (i32.const 1))
  1280      )
  1281    ))
  1282    "type mismatch"
  1283  )
  1284  
  1285  (assert_invalid
  1286    (module
  1287      (func $type-condition-empty
  1288        (if (then))
  1289      )
  1290    )
  1291    "type mismatch"
  1292  )
  1293  (assert_invalid
  1294    (module
  1295      (func $type-condition-empty-in-block
  1296        (i32.const 0)
  1297        (block (if (then)))
  1298      )
  1299    )
  1300    "type mismatch"
  1301  )
  1302  (assert_invalid
  1303    (module
  1304      (func $type-condition-empty-in-loop
  1305        (i32.const 0)
  1306        (loop (if (then)))
  1307      )
  1308    )
  1309    "type mismatch"
  1310  )
  1311  (assert_invalid
  1312    (module
  1313      (func $type-condition-empty-in-then
  1314        (i32.const 0) (i32.const 0)
  1315        (if (then (if (then))))
  1316      )
  1317    )
  1318    "type mismatch"
  1319  )
  1320  (assert_invalid
  1321    (module
  1322      (func $type-condition-empty-in-else
  1323        (i32.const 0) (i32.const 0)
  1324        (if (result i32) (then (i32.const 0)) (else (if (then)) (i32.const 0)))
  1325        (drop)
  1326      )
  1327    )
  1328    "type mismatch"
  1329  )
  1330  (assert_invalid
  1331    (module
  1332      (func $type-condition-empty-in-br
  1333        (i32.const 0)
  1334        (block (br 0 (if(then))) (drop))
  1335      )
  1336    )
  1337    "type mismatch"
  1338  )
  1339  (assert_invalid
  1340    (module
  1341      (func $type-condition-empty-in-br_if
  1342        (i32.const 0)
  1343        (block (br_if 0 (if(then)) (i32.const 1)) (drop))
  1344      )
  1345    )
  1346    "type mismatch"
  1347  )
  1348  (assert_invalid
  1349    (module
  1350      (func $type-condition-empty-in-br_table
  1351        (i32.const 0)
  1352        (block (br_table 0 (if(then))) (drop))
  1353      )
  1354    )
  1355    "type mismatch"
  1356  )
  1357  (assert_invalid
  1358    (module
  1359      (func $type-condition-empty-in-return
  1360        (return (if(then))) (drop)
  1361      )
  1362    )
  1363    "type mismatch"
  1364  )
  1365  (assert_invalid
  1366    (module
  1367      (func $type-condition-empty-in-select
  1368        (select (if(then)) (i32.const 1) (i32.const 2)) (drop)
  1369      )
  1370    )
  1371    "type mismatch"
  1372  )
  1373  (assert_invalid
  1374    (module
  1375      (func $type-condition-empty-in-call
  1376        (call 1 (if(then))) (drop)
  1377      )
  1378      (func (param i32) (result i32) (local.get 0))
  1379    )
  1380    "type mismatch"
  1381  )
  1382  (assert_invalid
  1383    (module
  1384      (func $f (param i32) (result i32) (local.get 0))
  1385      (type $sig (func (param i32) (result i32)))
  1386      (table funcref (elem $f))
  1387      (func $type-condition-empty-in-call_indirect
  1388        (block (result i32)
  1389          (call_indirect (type $sig)
  1390            (if(then)) (i32.const 0)
  1391          )
  1392          (drop)
  1393        )
  1394      )
  1395    )
  1396    "type mismatch"
  1397  )
  1398  (assert_invalid
  1399    (module
  1400      (func $type-condition-empty-in-local.set
  1401        (local i32)
  1402        (local.set 0 (if(then))) (local.get 0) (drop)
  1403      )
  1404    )
  1405    "type mismatch"
  1406  )
  1407  (assert_invalid
  1408    (module
  1409      (func $type-condition-empty-in-local.tee
  1410        (local i32)
  1411        (local.tee 0 (if(then))) (drop)
  1412      )
  1413    )
  1414    "type mismatch"
  1415  )
  1416  (assert_invalid
  1417    (module
  1418      (global $x (mut i32) (i32.const 0))
  1419      (func $type-condition-empty-in-global.set
  1420        (global.set $x (if(then))) (global.get $x) (drop)
  1421      )
  1422    )
  1423    "type mismatch"
  1424  )
  1425  (assert_invalid
  1426    (module
  1427      (memory 0)
  1428      (func $type-condition-empty-in-memory.grow
  1429        (memory.grow (if(then))) (drop)
  1430      )
  1431    )
  1432    "type mismatch"
  1433  )
  1434  (assert_invalid
  1435    (module
  1436      (memory 0)
  1437      (func $type-condition-empty-in-load
  1438        (i32.load (if(then))) (drop)
  1439      )
  1440    )
  1441    "type mismatch"
  1442  )
  1443  (assert_invalid
  1444    (module
  1445      (memory 1)
  1446      (func $type-condition-empty-in-store
  1447        (i32.store (if(then)) (i32.const 1))
  1448      )
  1449    )
  1450    "type mismatch"
  1451  )
  1452  
  1453  (assert_invalid
  1454    (module (func $type-param-void-vs-num
  1455      (if (param i32) (i32.const 1) (then (drop)))
  1456    ))
  1457    "type mismatch"
  1458  )
  1459  (assert_invalid
  1460    (module (func $type-param-void-vs-nums
  1461      (if (param i32 f64) (i32.const 1) (then (drop) (drop)))
  1462    ))
  1463    "type mismatch"
  1464  )
  1465  (assert_invalid
  1466    (module (func $type-param-num-vs-num
  1467      (f32.const 0) (if (param i32) (i32.const 1) (then (drop)))
  1468    ))
  1469    "type mismatch"
  1470  )
  1471  (assert_invalid
  1472    (module (func $type-param-num-vs-nums
  1473      (f32.const 0) (if (param f32 i32) (i32.const 1) (then (drop) (drop)))
  1474    ))
  1475    "type mismatch"
  1476  )
  1477  (assert_invalid
  1478    (module (func $type-param-nested-void-vs-num
  1479      (block (if (param i32) (i32.const 1) (then (drop))))
  1480    ))
  1481    "type mismatch"
  1482  )
  1483  (assert_invalid
  1484    (module (func $type-param-void-vs-nums
  1485      (block (if (param i32 f64) (i32.const 1) (then (drop) (drop))))
  1486    ))
  1487    "type mismatch"
  1488  )
  1489  (assert_invalid
  1490    (module (func $type-param-num-vs-num
  1491      (block (f32.const 0) (if (param i32) (i32.const 1) (then (drop))))
  1492    ))
  1493    "type mismatch"
  1494  )
  1495  (assert_invalid
  1496    (module (func $type-param-num-vs-nums
  1497      (block (f32.const 0) (if (param f32 i32) (i32.const 1) (then (drop) (drop))))
  1498    ))
  1499    "type mismatch"
  1500  )
  1501  
  1502  (assert_malformed
  1503    (module quote "(func (param i32) (result i32) if (param $x i32) end)")
  1504    "unexpected token"
  1505  )
  1506  (assert_malformed
  1507    (module quote "(func (param i32) (result i32) (if (param $x i32) (then)))")
  1508    "unexpected token"
  1509  )
  1510  
  1511  (assert_malformed
  1512    (module quote "(func i32.const 0 if end $l)")
  1513    "mismatching label"
  1514  )
  1515  (assert_malformed
  1516    (module quote "(func i32.const 0 if $a end $l)")
  1517    "mismatching label"
  1518  )
  1519  (assert_malformed
  1520    (module quote "(func i32.const 0 if else $l end)")
  1521    "mismatching label"
  1522  )
  1523  (assert_malformed
  1524    (module quote "(func i32.const 0 if $a else $l end)")
  1525    "mismatching label"
  1526  )
  1527  (assert_malformed
  1528    (module quote "(func i32.const 0 if else end $l)")
  1529    "mismatching label"
  1530  )
  1531  (assert_malformed
  1532    (module quote "(func i32.const 0 if else $l end $l)")
  1533    "mismatching label"
  1534  )
  1535  (assert_malformed
  1536    (module quote "(func i32.const 0 if else $l1 end $l2)")
  1537    "mismatching label"
  1538  )
  1539  (assert_malformed
  1540    (module quote "(func i32.const 0 if $a else end $l)")
  1541    "mismatching label"
  1542  )
  1543  (assert_malformed
  1544    (module quote "(func i32.const 0 if $a else $a end $l)")
  1545    "mismatching label"
  1546  )
  1547  (assert_malformed
  1548    (module quote "(func i32.const 0 if $a else $l end $l)")
  1549    "mismatching label"
  1550  )