From 2cf8c44e43a2b9bd1e3dc1155c3aaa5892911234 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sat, 7 Feb 2009 23:30:41 +0000 Subject: [PATCH] Add a simple RAII object, to be used for pushing a cleanup entry and make the insertion point be the cleanup block. llvm-svn: 64048 --- clang/lib/CodeGen/CodeGenFunction.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 068627139d79..1f037600f51f 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -132,6 +132,25 @@ public: /// and return a BasicBlock where cleanup instructions can be added llvm::BasicBlock *CreateCleanupBlock(); + /// CleanupScope - RAII object that will create a cleanup block and + /// set the insert point to that block. When destructed, it sets the insert + /// point to the previous block. + class CleanupScope { + CodeGenFunction& CGF; + llvm::BasicBlock *CurBB; + + public: + CleanupScope(CodeGenFunction &cgf) + : CGF(cgf), CurBB(CGF.Builder.GetInsertBlock()) { + llvm::BasicBlock *FinallyBB = CGF.CreateCleanupBlock(); + CGF.Builder.SetInsertPoint(FinallyBB); + } + + ~CleanupScope() { + CGF.Builder.SetInsertPoint(CurBB); + } + }; + private: /// LabelIDs - Track arbitrary ids assigned to labels for use in /// implementing the GCC address-of-label extension and indirect