From 6a3b31af5dbb22749e6d5a1cad9dfaab6863b615 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 17 Oct 2026 08:36:19 +0000 Subject: feat(classes): destroy stack objects during exception unwinding Co-Authored-By: Claude Opus 5.5 --- include/cps/ExceptionHandler.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'include/cps/ExceptionHandler.h') diff --git a/include/cps/ExceptionHandler.h b/include/cps/ExceptionHandler.h index 5c846ae..a2dc5d0 100644 --- a/include/cps/ExceptionHandler.h +++ b/include/cps/ExceptionHandler.h @@ -2,6 +2,7 @@ #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Module.h" #include +#include #include namespace cps { @@ -17,8 +18,16 @@ class ExceptionHandler { struct FunctionState { std::vector Handlers; unsigned CatchDepth = 0; + bool HasCleanups = false; }; + struct CleanupPoint { + llvm::Instruction *Before; + FunctionState State; + bool Unwinding; + }; + std::map> CleanupPoints; + bool FillingUnwind = false; llvm::LLVMContext &Context; llvm::IRBuilder<> &Builder; llvm::Module &Module; @@ -38,7 +47,10 @@ public: llvm::AllocaInst *popHandler(); void beginCatch(llvm::AllocaInst *Exception); void endCatch(); - void emitReturnCleanup(); + llvm::Instruction *emitReturnCleanup(); + void enableCleanups(llvm::Function *F); + void recordExit(llvm::Instruction *Before, bool Unwinding = false); + void fillCleanups(llvm::Function *F, const std::function &Destroy); llvm::Value *emitCall(llvm::FunctionCallee Callee, llvm::ArrayRef Args, const llvm::Twine &Name = ""); -- cgit v1.3.1-4-g156e