diff options
author | Anders Carlsson <andersca@mac.com> | 2009-02-07 23:50:39 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-02-07 23:50:39 +0000 |
commit | c71c845fe77ee1f891d60232ec320912d88557ee (patch) | |
tree | 6840ef596be59af3874b6de10924f5e0843ad47c /lib | |
parent | 0d5c6851393d260dfb5ab0420b50adc173e1c549 (diff) |
Add support for emitting cleanup blocks. Make EmitCompoundStatement emit cleanup blocks if necessary
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64051 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/CGStmt.cpp | 7 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.cpp | 21 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.h | 7 |
3 files changed, 34 insertions, 1 deletions
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index ac97c6329d..fc7a7c7f8f 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -123,7 +123,7 @@ bool CodeGenFunction::EmitSimpleStmt(const Stmt *S) { /// (for use by the statement expression extension). RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast, llvm::Value *AggLoc, bool isAggVol) { - // FIXME: handle vla's etc. + CGDebugInfo *DI = CGM.getDebugInfo(); if (DI) { EnsureInsertPoint(); @@ -131,6 +131,9 @@ RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast, DI->EmitRegionStart(CurFn, Builder); } + // Keep track of the current cleanup stack depth. + size_t CleanupStackDepth = CleanupEntries.size(); + // Push a null stack save value. StackSaveValues.push_back(0); @@ -171,6 +174,8 @@ RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast, Builder.CreateCall(F, V); } + EmitCleanupBlocks(CleanupStackDepth); + return RV; } diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 4ba4d600f8..838de70218 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -521,3 +521,24 @@ llvm::BasicBlock *CodeGenFunction::CreateCleanupBlock() return CleanupBlock; } + +void CodeGenFunction::EmitCleanupBlocks(size_t OldCleanupStackSize) +{ + assert(CleanupEntries.size() >= OldCleanupStackSize && + "Cleanup stack mismatch!"); + + while (CleanupEntries.size() > OldCleanupStackSize) + EmitCleanupBlock(); +} + +void CodeGenFunction::EmitCleanupBlock() +{ + CleanupEntry &CE = CleanupEntries.back(); + + llvm::BasicBlock *CleanupBlock = CE.CleanupBlock; + + CleanupEntries.pop_back(); + + EmitBlock(CleanupBlock); +} + diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 1f037600f5..8a0220724e 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -151,6 +151,10 @@ public: } }; + /// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup + /// blocks that have been added. + void EmitCleanupBlocks(size_t OldCleanupStackSize); + private: /// LabelIDs - Track arbitrary ids assigned to labels for use in /// implementing the GCC address-of-label extension and indirect @@ -762,6 +766,9 @@ private: llvm::Value* EmitAsmInput(const AsmStmt &S, TargetInfo::ConstraintInfo Info, const Expr *InputExpr, std::string &ConstraintStr); + /// EmitCleanupBlock - emits a single cleanup block. + void EmitCleanupBlock(); + }; } // end namespace CodeGen } // end namespace clang |