================
@@ -213,30 +217,57 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
CGF.EmitStmt(S.getTryBody());
// Leave the try.
- if (S.getNumCatchStmts())
- CGF.popCatchScope();
+ llvm::BasicBlock *DispatchBlock = nullptr;
+ if (S.getNumCatchStmts()) {
+ DispatchBlock = CGF.popCatchScope();
+ }
+
+ // TODO(hugo): Better documentation
+ // Wasm uses Windows-style EH instructions, but merges all catch clauses into
+ // one big catchpad. So we save the old funclet pad here before we traverse
+ // each catch handler.
+ SaveAndRestore RestoreCurrentFuncletPad(CGF.CurrentFuncletPad);
+ llvm::BasicBlock *WasmCatchStartBlock = nullptr;
+ llvm::CatchPadInst *CPI = nullptr;
+ if (!!DispatchBlock && IsWasm) {
+ auto *CatchSwitch =
+ cast<llvm::CatchSwitchInst>(DispatchBlock->getFirstNonPHIIt());
+ WasmCatchStartBlock = CatchSwitch->hasUnwindDest()
+ ? CatchSwitch->getSuccessor(1)
+ : CatchSwitch->getSuccessor(0);
+ CPI =
+ cast<llvm::CatchPadInst>(WasmCatchStartBlock->getFirstNonPHIIt());
+ CGF.CurrentFuncletPad = CPI;
+ }
// Remember where we were.
CGBuilderTy::InsertPoint SavedIP = CGF.Builder.saveAndClearIP();
// Emit the handlers.
+ // TODO(hugo): Document
----------------
Midar wrote:
Please add before merging :). Same above.
// Edit: I see you addressed the one above in a later commit, but not this one.
https://github.com/llvm/llvm-project/pull/183753
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits