[clang] [CodeGen] Implement Objective-C WebAssembly exception handling support (PR #215562)
Hendrik Hübner via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 22 12:27:48 PDT 2026
================
@@ -182,61 +195,122 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
Handler.TypeInfo = GetEHType(CatchDecl->getType());
}
+ // Create a new catch scope
EHCatchScope *Catch = CGF.EHStack.pushCatch(Handlers.size());
for (unsigned I = 0, E = Handlers.size(); I != E; ++I)
Catch->setHandler(I, { Handlers[I].TypeInfo, Handlers[I].Flags }, Handlers[I].Block);
}
- if (useFunclets)
+ if (IsMSVC) {
if (const ObjCAtFinallyStmt *Finally = S.getFinallyStmt()) {
- CodeGenFunction HelperCGF(CGM, /*suppressNewContext=*/true);
- if (!CGF.CurSEHParent)
- CGF.CurSEHParent = cast<NamedDecl>(CGF.CurFuncDecl);
- // Outline the finally block.
- const Stmt *FinallyBlock = Finally->getFinallyBody();
- HelperCGF.startOutlinedSEHHelper(CGF, /*isFilter*/false, FinallyBlock);
-
- // Emit the original filter expression, convert to i32, and return.
- HelperCGF.EmitStmt(FinallyBlock);
+ CodeGenFunction HelperCGF(CGM, /*suppressNewContext=*/true);
+ if (!CGF.CurSEHParent)
+ CGF.CurSEHParent = cast<NamedDecl>(CGF.CurFuncDecl);
+ // Outline the finally block.
+ const Stmt *FinallyBlock = Finally->getFinallyBody();
+ HelperCGF.startOutlinedSEHHelper(CGF, /*isFilter*/ false, FinallyBlock);
- HelperCGF.FinishFunction(FinallyBlock->getEndLoc());
+ // Emit the original filter expression, convert to i32, and return.
+ HelperCGF.EmitStmt(FinallyBlock);
- llvm::Function *FinallyFunc = HelperCGF.CurFn;
+ HelperCGF.FinishFunction(FinallyBlock->getEndLoc());
+ llvm::Function *FinallyFunc = HelperCGF.CurFn;
- // Push a cleanup for __finally blocks.
- CGF.pushSEHCleanup(NormalAndEHCleanup, FinallyFunc);
+ // Push a cleanup for __finally blocks.
+ CGF.pushSEHCleanup(NormalAndEHCleanup, FinallyFunc);
}
-
+ }
// Emit the try body.
CGF.EmitStmt(S.getTryBody());
+ // lpad or catch.dispatch (the dispatch block) has now been emitted
+ //
+ // Here an example:
+ // void may_throw();
+ // @try {
+ // may_throw();
+ // } @catch(id a) {
+ // } @catch(id b) {
+ // [...]
+ //
+ // With funclet-based exception handling, the dispatch block is created in
+ // getEHDispatchBlock() <- getInvokeDestImpl() <- EmitCall().
+ // The following IR is emitted in this case:
+ // On aarch64-linux-gnu (landing-pad based)
+ // %call = invoke i32 @may_throw()
+ // to label %invoke.cont unwind label %lpad, !dbg !19
+ // On aarch64-pc-windows-msvc (funclet based)
----------------
HendrikHuebner wrote:
I think these comments are a bit too verbose actually. I'd rather replace them with shorter ones.
https://github.com/llvm/llvm-project/pull/215562
More information about the cfe-commits
mailing list