Skip to content

Add support for Wasm EH#5162

Open
QuantumSegfault wants to merge 1 commit into
ldc-developers:masterfrom
QuantumSegfault:wasm-eh
Open

Add support for Wasm EH#5162
QuantumSegfault wants to merge 1 commit into
ldc-developers:masterfrom
QuantumSegfault:wasm-eh

Conversation

@QuantumSegfault

Copy link
Copy Markdown
Contributor

Adds codegen and DRuntime support for WebAssembly exception handling.

@QuantumSegfault

Copy link
Copy Markdown
Contributor Author

Some IR comparisons for reference

C++/Clang: https://godbolt.org/z/heMqqGvbb
D/LDC (this PR): https://godbolt.org/z/vMYWYvPE5

@QuantumSegfault

Copy link
Copy Markdown
Contributor Author

@kinke

Maybe @rainers?

It works, but maybe one of you has a better idea on how to organize the modifications to gen/trycatchfinally.cpp.

Wasm EH follows MSVC style catchpad/catchswitch/catchret & cleanpad/cleanupret. However there is only one catchswitch per catchpad, after which an Itanium-landingpad-style comparison chain needs to be emitted to determine the correct catch block (if any).

Right now I'm treating it more like MSVC, and just dumping everything in emitCatchBodies...though this requires exposing some TryCatchFinallyScope internals...

@rainers

rainers commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Sorry, it's been so long since I worked on the EH, I don't remember any details. I doubt I can be of any help here.

@QuantumSegfault

Copy link
Copy Markdown
Contributor Author

Sorry, it's been so long since I worked on the EH, I don't remember any details. I doubt I can be of any help here.

That's unfortunate...

Do you know of anyone else who might be more familiar with the EH code at this point (MSVC especially)?

@rainers

rainers commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

I suspect that would only be @kinke.

@kinke

kinke commented Jul 3, 2026

Copy link
Copy Markdown
Member

Cool, thanks for tackling this! - Unfortunately I'm not really familiar with the MSVC EH stuff either, as Rainer thankfully did all the work. ;) It has just come up again though, as related #3504 becomes more pressing, being a blocker for the D v2.113 merge in #5113 (comment). I really hate that LLVM doesn't take care of this for us (accepting the generic Itanium EH IR representation for all targets and lowering it appropriately as needed).

@QuantumSegfault QuantumSegfault marked this pull request as ready for review July 4, 2026 07:46
@QuantumSegfault

Copy link
Copy Markdown
Contributor Author

Cool, thanks for tackling this! - Unfortunately I'm not really familiar with the MSVC EH stuff either, as Rainer thankfully did all the work. ;) It has just come up again though, as related #3504 becomes more pressing, being a blocker for the D v2.113 merge in #5113 (comment). I really hate that LLVM doesn't take care of this for us (accepting the generic Itanium EH IR representation for all targets and lowering it appropriately as needed).

Okay, then I guess we just have to consider what we have, and ignore prior rationale.

On one hand, doing what I did works, and makes it fairly easy to keep it inline with any fixes to MSVC EH (which will most likely impact Wasm EH as well).

On the other hand, it's kind of ugly from a code cleanliness point of view, cause I'm jamming what should probably go into emitLandingPad into emitWasmCatchBodies. Then again, MSVC EH seems to be using emitLandingPad to manage cleanup scopes really, not true landing pads. Try to fit in into there seems like it would be more difficult.

I mean, technically we could always refactor it later, right? But when's "later"?

I guess I'll just mark this "Ready for review" and we'll go from there.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants