WebAssembly / WebAssembly/wabt

`wast2json` miscompiles "if.wast" from the specification tests

Open
#2,417 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
8.1k
Forks
827
Avg merge
4d 6h
Merged PRs (30d)
18

Description

The following WAST test expression from if.wast miscompiles, omitting the empty else block:

(assert_invalid
  (module (func $type-else-value-empty-vs-num (result i32)
    (if (result i32) (i32.const 1) (then (i32.const 0)) (else))
  ))
  "type mismatch"
)
$ wast2json if.wast
$ wasm-objdump -x -d if.0.wasm

if.0.wasm:	file format wasm 0x1

Section Details:

Type[1]:
 - type[0] () -> i32
Function[1]:
 - func[0] sig=0
Code[1]:
 - func[0] size=9

Code Disassembly:

000017 func[0]:
 000018: 41 01                      | i32.const 1
 00001a: 04 7f                      | if i32
 00001c: 41 00                      |   i32.const 0
 00001e: 0b                         | end
 00001f: 0b                         | end

WABT version: 0df6c26d2a6122afcc2c32ff6b608326258d40d9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with wast2json if.wast, then inspect the wast2json entry point and the handling of the WAST if expression containing an empty else block. Compare the generated if.0.wasm with the source expression and wasm-objdump output; done means the empty else block is preserved and the invalid type mismatch remains represented correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.