Skip to content

Optimizing functions with anyref locals runs into assertion #2444

Description

@dcodeIO

I'm currently trying to track down a Binaryen assertion happening with the following module:

(module
  (import "ref" "null" (global $ref_null anyref))
  (import "ref" "is_null" (func $ref_is_null (param anyref) (result i32)))
  (func $test
    (local $0 anyref)
    (local.set $0
      (global.get $ref_null)
    )
    (drop
      (call $ref_is_null
        (local.get $0)
      )
    )
    ;; remove this to make it work:
    (drop
      (call $ref_is_null
        (local.get $0)
      )
    )
  )
  (export $test $test)
)

which yields

abort(Assertion failed: false, at: ./src/literal.h,87,makeFromInt32)

when I attempt to optimize it with optimizeLevel > 1. The problem goes away if I remove the second

    (drop
      (call $ref_is_null
        (local.get $0)
      )
    )

from the function or make $0 a function parameter, so I guess that there is an optimization trying to move/copy local values around that causes this as soon as there are two local.gets of the same anyref local or something along those lines. This isn't overly important, just ran into this while trying to polyfill ref.null etc. so we can have shiny things. Perhaps there's an easy fix?

Activity

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

Metadata

Metadata

Assignees

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