summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGException.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-07-21 00:52:03 +0000
committerJohn McCall <rjmccall@apple.com>2010-07-21 00:52:03 +0000
commit1e67040fb7cf918f3cf0fc990390953e476e8219 (patch)
tree3d7c5f103ef5274066fbc2db94702e2fdc362415 /clang/lib/CodeGen/CGException.cpp
parentc713b9665b2c7012d1d8f29ff21b681f543ee95f (diff)
downloadbcm5719-llvm-1e67040fb7cf918f3cf0fc990390953e476e8219.tar.gz
bcm5719-llvm-1e67040fb7cf918f3cf0fc990390953e476e8219.zip
Convert the end-catch call for finally blocks to a lazy cleanup. This kills off
the last of the shared-code cleanups. llvm-svn: 108975
Diffstat (limited to 'clang/lib/CodeGen/CGException.cpp')
-rw-r--r--clang/lib/CodeGen/CGException.cpp38
1 files changed, 25 insertions, 13 deletions
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index 4649b901567..f0c1d5193d0 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1337,6 +1337,28 @@ void CodeGenFunction::ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock) {
EmitBlock(ContBB);
}
+namespace {
+ struct CallEndCatchForFinally : EHScopeStack::LazyCleanup {
+ llvm::Value *ForEHVar;
+ llvm::Value *EndCatchFn;
+ CallEndCatchForFinally(llvm::Value *ForEHVar, llvm::Value *EndCatchFn)
+ : ForEHVar(ForEHVar), EndCatchFn(EndCatchFn) {}
+
+ void Emit(CodeGenFunction &CGF, bool IsForEH) {
+ llvm::BasicBlock *EndCatchBB = CGF.createBasicBlock("finally.endcatch");
+ llvm::BasicBlock *CleanupContBB =
+ CGF.createBasicBlock("finally.cleanup.cont");
+
+ llvm::Value *ShouldEndCatch =
+ CGF.Builder.CreateLoad(ForEHVar, "finally.endcatch");
+ CGF.Builder.CreateCondBr(ShouldEndCatch, EndCatchBB, CleanupContBB);
+ CGF.EmitBlock(EndCatchBB);
+ CGF.EmitCallOrInvoke(EndCatchFn, 0, 0); // catch-all, so might throw
+ CGF.EmitBlock(CleanupContBB);
+ }
+ };
+}
+
/// Enters a finally block for an implementation using zero-cost
/// exceptions. This is mostly general, but hard-codes some
/// language/ABI-specific behavior in the catch-all sections.
@@ -1392,19 +1414,9 @@ CodeGenFunction::EnterFinallyBlock(const Stmt *Body,
CodeGenFunction::CleanupBlock Cleanup(*this, NormalCleanup);
// Enter a cleanup to call the end-catch function if one was provided.
- if (EndCatchFn) {
- CodeGenFunction::CleanupBlock FinallyExitCleanup(CGF, NormalAndEHCleanup);
-
- llvm::BasicBlock *EndCatchBB = createBasicBlock("finally.endcatch");
- llvm::BasicBlock *CleanupContBB = createBasicBlock("finally.cleanup.cont");
-
- llvm::Value *ShouldEndCatch =
- Builder.CreateLoad(ForEHVar, "finally.endcatch");
- Builder.CreateCondBr(ShouldEndCatch, EndCatchBB, CleanupContBB);
- EmitBlock(EndCatchBB);
- EmitCallOrInvoke(EndCatchFn, 0, 0); // catch-all, so might throw
- EmitBlock(CleanupContBB);
- }
+ if (EndCatchFn)
+ EHStack.pushLazyCleanup<CallEndCatchForFinally>(NormalAndEHCleanup,
+ ForEHVar, EndCatchFn);
// Emit the finally block.
EmitStmt(Body);
OpenPOWER on IntegriCloud