Skip to content

wasm-opt generates invalid wasm with -all #7344

@peter-jerry-ye

Description

@peter-jerry-ye

For the given wat file, run

wasm-tools print input.wat | wasm-opt -O1 -S -o - - | wasm-tools validate
wasm-tools print input.wat | wasm-opt -all -O1 -S -o - - | wasm-tools validate

The first one (without -all) works fine, but the second one (with -all) will fail to validate.

Version: 122

Input (shrunk by wasm-tools):

(module
  (type (;0;) (func (result i32)))
  (type (;1;) (func (param i32) (result i32)))
  (export "" (func 3))
  (func (;0;) (type 0) (result i32)
    unreachable
  )
  (func (;1;) (type 0) (result i32)
    unreachable
  )
  (func (;2;) (type 1) (param i32) (result i32)
    (local i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)
    i32.const 0
    loop (type 1) (param i32) (result i32) ;; label = @1
      local.tee 1
      i32.const 15
      i32.add
      local.tee 38
      i32.const -16
      i32.and
      local.set 2
      local.get 2
      if ;; label = @2
        local.get 11
        if ;; label = @3
        else
        end
        local.get 4
        return
      else
      end
      i32.const 0
      if (result i32) ;; label = @2
        i32.const 0
        local.set 22
        local.get 6
        if ;; label = @3
          i32.const 1
          return
        else
        end
        local.get 2
        br 1 (;@1;)
      else
        local.get 6
        if ;; label = @3
        else
          i32.const 0
          return
        end
        i32.const 0
        local.set 29
        i32.const 0
        local.set 30
        call 0
        local.set 26
        local.get 9
        local.set 27
        local.get 26
        local.set 24
        local.get 2
        br 1 (;@1;)
      end
    end
  )
  (func (;3;) (type 1) (param i32) (result i32)
    (local i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)
    local.get 10
    if (result i32) ;; label = @1
      i32.const 1
    else
      call 1
    end
    i32.eqz
    if ;; label = @1
    else
    end
    i32.const 0
    if (result i32) ;; label = @1
      local.get 0
      if ;; label = @2
        local.get 2
        return
      else
      end
      i32.const 0
      if ;; label = @2
        local.get 4
        local.set 23
        i32.const 0
        local.set 24
        i32.const 1
        local.set 25
        local.get 3
        local.set 26
        local.get 3
        local.set 27
        local.get 4
        return
      else
      end
      i32.const 1
      if ;; label = @2
        local.get 5
        if ;; label = @3
          local.get 6
          local.set 32
          i32.const 0
          local.set 33
          i32.const 1
          local.set 34
          local.get 5
          local.set 35
          local.get 6
          return
        else
        end
      else
      end
      i32.const 0
    else
      local.get 0
      local.get 0
      call 2
      i32.ne
      if (result i32) ;; label = @2
        i32.const 0
      else
        i32.const 0
      end
    end
  )
)

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