Skip to content

branching to invalid label? #270

Closed
Closed

Description

@wanderer

What is (br 0) branching too?

(module
  (func $if (result i32)
    (local $i i32)
    (if
      (i32.const 1)
      (br 0)
     )
     (get_local $i)
  )
  (export "if" $if)
)

There are no blocks or loops so there are no labels.

Activity

  1. wanderer commented on Mar 31, 2016

    @wanderer
    Author

    thanks @JSStats. There is no special if-then block in the binary spec, so it must be getting converted to this

    (module
      (func $if (result i32)
        (local $i i32)
        (if
          (i32.const 1)
          (block (br 0) ) 
         )
         (get_local $i)
      )
      (export "if" $if)
    )
    

    But why is it inserting a block? Shouldn't the s-expressions be 1-1 with the binary?

  2. wanderer commented on Mar 31, 2016

    @wanderer
    Author

    @JSStats I think i see that. I'm picking it apart with the sexpr-wasm-prototype. So something like

        (if
          (i32.const 1)
          (i32.const 1)
         )
    

    Gets no block inserted. But

        (if
          (i32.const 1)
          (br 0)
         )
    

    gets turned into

        (if
          (i32.const 1)
          (block (br 0))
         )
    

    Which is annoying because there must be some rules to decide whether or not to insert a block. Also it means s-expressions are not 1-1 with the binary

  3. wanderer commented on Mar 31, 2016

    @wanderer
    Author

    thanks @JSStats for taking time to explain

  4. binji commented on Mar 31, 2016

    @binji
    Member

    @JSStats No, that's wrong. AIUI, the spec was updated before the demo to add blocks to the then and else branches, in preparation for the transition to the postorder format. But the binary format was not similarly updated. I modified sexpr-wasm-prototype so it could take this discrepancy into account (AFAIK the other binary translators don't bother).

  5. added a commit that references this issue on Oct 3, 2023
  6. added a commit that references this issue on Jul 23, 2024
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