Skip to content

wasm-merge deletes unreachable instruction when emitting text format. #6219

Description

@doehyunbaek
(module
(memory 1)
(func (export "_start") (;3480;) (param i32 i32) (result i32)
    local.get 0
    i32.load
    drop
    loop  ;; label = @1
      br 0 (;@1;)
    end
    unreachable)
)
# this is fine
~/binaryen-report/unreachable_missing wat2wasm unreachable.wat && wasm-merge unreachable.wasm bug -o merged.wasm && wasm-validate merged.wasm
# this is not fine
~/binaryen-report/unreachable_missing wat2wasm unreachable.wat && wasm-merge unreachable.wasm bug -S -o merged.wat && wat2wasm merged.wat
merged.wat:11:3: error: type mismatch in implicit return, expected [i32] but got []
  (loop $label$1
  ^
~/binaryen-report/unreachable_missing cat merged.wat
(module
 (type $0 (func (param i32 i32) (result i32)))
 (memory $0 1)
 (export "_start" (func $0))
 (func $0 (param $0 i32) (param $1 i32) (result i32)
  (drop
   (i32.load
    (local.get $0)
   )
  )
  (loop $label$1
   (br $label$1)
  )
 )
)

It seems the cause is that unreachable is missing in textual emit case.

Code is also at this repo.

If this is a duplicate issue or non-issue, sorry in advance. Feel free to close the issue in that case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions