WebAssembly / WebAssembly/wabt

wasm-decompile cannot handle branching out of a function

Open
#1,603 0 comments 3 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

wasm-decompile fails to decompile the binary corresponding to the following code for instance:

(module
    (func (result i32)
        (block (result i32)
            (i32.const 42)
            (i32.const 1)
            (br_if 1)
        )
    )
)

It fails with the following:

wasm-decompile: wabt/src/ir.h:57: const string& wabt::Var::name() const: Assertion `is_name()' failed.

Trace:

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ffff7699921 in __GI_abort () at abort.c:79
#2  0x00007ffff768948a in __assert_fail_base (fmt=0x7ffff7810750 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x5555557959e9 "is_name()",
    file=file@entry=0x5555557959b8 "wabt/src/ir.h", line=line@entry=57,
    function=function@entry=0x555555795aa0 <wabt::Var::name[abi:cxx11]() const::__PRETTY_FUNCTION__> "const string& wabt::Var::name() const") at assert.c:92
#3  0x00007ffff7689502 in __GI___assert_fail (assertion=0x5555557959e9 "is_name()", file=0x5555557959b8 "wabt/src/ir.h", line=57,
    function=0x555555795aa0 <wabt::Var::name[abi:cxx11]() const::__PRETTY_FUNCTION__> "const string& wabt::Var::name() const") at assert.c:101
#4  0x00005555556c34f7 in wabt::Var::name[abi:cxx11]() const (this=0x555555a70fe0) at wabt/src/ir.h:57
#5  0x00005555557096db in wabt::Decompiler::DecompileExpr (this=0x7fffffffd3b0, n=..., parent=0x555555a71030) at wabt/src/decompiler.cc:552
#6  0x00005555557075c1 in wabt::Decompiler::DecompileExpr (this=0x7fffffffd3b0, n=..., parent=0x555555a711b0) at wabt/src/decompiler.cc:339
#7  0x00005555557075c1 in wabt::Decompiler::DecompileExpr (this=0x7fffffffd3b0, n=..., parent=0x555555a714d0) at wabt/src/decompiler.cc:339
#8  0x00005555557075c1 in wabt::Decompiler::DecompileExpr (this=0x7fffffffd3b0, n=..., parent=0x0) at wabt/src/decompiler.cc:339
#9  0x000055555570b3ad in wabt::Decompiler::Decompile[abi:cxx11]() (this=0x7fffffffd3b0) at wabt/src/decompiler.cc:797
#10 0x00005555557019cc in wabt::Decompile[abi:cxx11](wabt::Module const&, wabt::DecompileOptions const&) (module=..., options=...) at wabt/src/decompiler.cc:826
#11 0x00005555556bcd57 in ProgramMain (argc=2, argv=0x7fffffffdb28) at wabt/src/tools/wasm-decompile.cc:104
#12 0x00005555556bcf23 in main (argc=2, argv=0x7fffffffdb28) at wabt/src/tools/wasm-decompile.cc:117

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 failure with the WebAssembly example using wasm-decompile, then inspect wabt/src/decompiler.cc around Decompiler::DecompileExpr at line 552 and follow the branch handling shown in the trace. Done means the example decompiles without the Var::name assertion failure.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.