[PATCH] D108582: [WebAssembly] Add Wasm SjLj option support for clang

Heejin Ahn via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 23 13:41:14 PDT 2021


aheejin created this revision.
aheejin added reviewers: dschuff, tlively.
Herald added subscribers: wingo, ecnelises, sunfish, jgravelle-google, sbc100.
aheejin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This adds support for Wasm SjLj in clang. Also this sets the new
`-mllvm -wasm-enable-eh` option for Wasm EH.

Note there is a little unfortunate inconsistency there: Wasm EH is
enabled by a clang option `-fwasm-exceptions`, which sets
`-mllvm -wasm-enable-eh` in the backend options. It also sets
`-exception-model=wasm` but this is done in the common code.

Wasm SjLj doesn't have a clang-level option like `-fwasm-exceptions`.
`-fwasm-exceptions` was added because each exception model has its
corresponding `-f***-exceptions`, but I'm not sure if adding a new
option like `-fwasm-sjlj` or something is a good idea.

So the current plan is Emscripten sets `-mllvm -wasm-enable-sjlj` if
Wasm SJLj is enabled in its settings.js, as it does for Emscripten
EH/SjLj (it sets `-mllvm -enable-emscripten-cxx-exceptions` for
Emscripten EH and `-mllvm -enable-emscripten-sjlj` for Emscripten SjLj).
And setting this enables the exception handling feature, and also sets
`-exception-model=wasm`, but this time this is not done in the common
code so we do it ourselves. It also sets the multivalue feature, because
for `longjmp` we throw two values and catch two values: the setjmp
buffer and the return value. So `catch` instruction will produce two
values.

Also note that other exception models have 1-to-1 correspondance with
their `-f***-exceptions` flag and their `-exception-model=***` flag, but
because we use `-exception-model=wasm` also for Wasm SjLj while
`-fwasm-exceptions` still means Wasm EH, there is also a little
inconsistency there, but I think it is manageable.

Also this adds various error checking and tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108582

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108582.368204.patch
Type: text/x-patch
Size: 8122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210823/aceb06db/attachment.bin>


More information about the cfe-commits mailing list