aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/ConstructorGen.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-17 08:36:19 +0000
committer_ov4 <ov4@ov4.org>2026-10-17 08:36:19 +0000
commit6a3b31af5dbb22749e6d5a1cad9dfaab6863b615 (patch)
tree58d2e7d956c8c605599a3f760040234ec2556d29 /lib/CodeGen/ConstructorGen.cc
parentabd56ef20bc8061bbecec29edd1301d324c2cb34 (diff)
feat(classes): destroy stack objects during exception unwinding
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/ConstructorGen.cc')
-rw-r--r--lib/CodeGen/ConstructorGen.cc16
1 files changed, 3 insertions, 13 deletions
diff --git a/lib/CodeGen/ConstructorGen.cc b/lib/CodeGen/ConstructorGen.cc
index c0e50ac..e1033c3 100644
--- a/lib/CodeGen/ConstructorGen.cc
+++ b/lib/CodeGen/ConstructorGen.cc
@@ -1,5 +1,6 @@
#include "cps/CodeGen.h"
#include "cps/MemoryHandler.h"
+#include "cps/ExceptionHandler.h"
#include "cps/TypeAST.h"
#include <climits>
#include <cstddef>
@@ -168,19 +169,8 @@ void CodeGen::emitStackObjectCleanup(const StackObject &Object) {
}
void CodeGen::finishStackObjects(Function *F) {
- IRBuilderBase::InsertPointGuard Guard(*Builder);
- std::vector<Instruction *> Exits;
- for (auto &BB : *F)
- if (BB.hasTerminator() && isa<ReturnInst>(BB.getTerminator()))
- Exits.push_back(BB.getTerminator());
- for (auto *Exit : Exits) {
- // Keep the original terminator in a continuation while cleanup builds branches.
- auto *BB = Exit->getParent();
- auto *Continuation = BB->splitBasicBlock(Exit->getIterator(), "after_destruction");
- BB->getTerminator()->eraseFromParent();
- Builder->SetInsertPoint(BB);
+ Exceptions->fillCleanups(F, [this] {
for (auto It = StackObjects.rbegin(); It != StackObjects.rend(); ++It)
emitStackObjectCleanup(*It);
- Builder->CreateBr(Continuation);
- }
+ });
}