Skip to content

Support try_table in Flatten #8372

Open

Description

@Pspritechologist

Parsing a WASM module using wasm-opt containing a try_table instruction yields the error [parse exception: bad node code 31 (at 0:9801)]. --debug prints the contents of the module up to the end of the function before the one containing the try_table. --enable-exception-handling is on and the throw instruction compiles perfectly fine.
I searched quite a lot but couldn't find any information regarding this, is there any way to get modern exceptions working with wasm-opt?

Activity

  1. kripken commented on Feb 24, 2026

    @kripken
    Member

    This is stable and tested:

    $ grep -r "(try_table " test/ | wc -l
    408
    

    Are you perhaps on an older version that does not have that support yet?

    (If you are on a recent version, perhaps you have a typo somehow, please provide a failing testcase.)

  2. Pspritechologist commented on Feb 25, 2026

    @Pspritechologist
    Author

    Are you perhaps on an older version that does not have that support yet?

    I had made sure that the wasm-opt installed via my package manager was up to date, but your question got me to run where wasm-opt and it turns out I had an older version installed via Cargo that was taking precedence 🙃
    Thank you, and sorry for the false report

    I'm now having a different issue, but I can open a separate issue for that (/keep debugging it) if desired.
    UNREACHABLE executed at /build/emscripten/src/binaryen/src/passes/Flatten.cpp:231! zsh: IOT instruction (core dumped)

  3. kripken commented on Feb 25, 2026

    @kripken
    Member

    The Flatten pass specifically does not yet support GC or Exceptions. But it is not normally run. What command are you using?

  4. Pspritechologist commented on Feb 25, 2026

    @Pspritechologist
    Author

    The Flatten pass specifically does not yet support GC or Exceptions. But it is not normally run. What command are you using?

    -O4, and that makes sense thank you :)
    I'll review the passes more closely.

  5. kripken commented on Feb 25, 2026

    @kripken
    Member

    Ok, then -O4 is not supported with all features. We should probably update the docs about it, though I hope we fix Flatten eventually...

  6. ttraenkler commented on Aug 21, 2026

    @ttraenkler

    We hit the same Flatten.cpp:231 assertion with wasm-opt -O4 on standardized-EH modules containing try_table, reproducible with Binaryen 125 and current main.

    Retrying with --skip-pass=flatten works: all remaining O4 passes complete and the output validates and runs correctly.

    Is try_table support in Flatten on the roadmap? If not, would you accept a minimal patch making Flatten gracefully skip functions containing unsupported EH/GC constructs instead of aborting the entire -O4 optimization?

  7. kripken commented on Aug 21, 2026

    @kripken
    Member

    @ttraenkler Hmm, I think we shouldn't make Flatten skip things, as e.g. Asyncify depends on Flatten actually running - it only works on the flattened form. That is, if Flatten skips a function, Asyncify would need to as well - but that means Asyncify is no longer valid.

    Is --skip-pass=flatten not a reasonable workaround for now? I don't have near-term plans to make Flatten work on try_table, but I hope someone else finds time (a PR would be welcome).

    Another option is to add --maybe-flatten which only flattens what it can, and -O4 would run that. I'd accept that PR too.

  8. ttraenkler commented on Aug 21, 2026

    @ttraenkler

    @kripken Thanks — agreed --skip-pass=flattenor --maybe-flatten sounds like the cleaner upstream solution until this can be implemented. I implemented a narrow fallback in our pipeline: when wasm-opt -O4 fails specifically because Flatten cannot process try_table, we retry that module with --skip-pass=flatten. If this workaround turns out not to be sufficient I will look into it further.

    I would suggest to reopen this issue to keep track of it. This surfaced because Wasmtime 47 rejects the legacy EH opcodes, while the current Binaryen Flatten pass does not yet handle standardized try_table so I assume others will hit this issue too.

  9. kripken commented on Aug 21, 2026

    @kripken
    Member

    Sounds good, reopening.

  10. changed the title [-]Error Parsing `try_table` Instruction[/-] [+]Support `try_table` in Flatten[/+] on Aug 21, 2026
  11. rayan-mazouz commented on Nov 30, 2026

    @rayan-mazouz

    A minimal reproduction, in case it helps whoever picks this up:

    (module
      (tag $e)
      (func (export "run") (result i32)
        (block $caught
          (try_table (catch $e $caught)
            (throw $e)))
        (i32.const 1)))

    Running the Flatten pass on it (Binaryen 133, through its C API, as wasm-opt --enable-exception-handling --flatten repro.wat does) aborts with unexpected expr type / UNREACHABLE executed at src/passes/Flatten.cpp:231, as does -O4 on any module holding a try_table.

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