diff options
| author | John McCall <rjmccall@apple.com> | 2010-08-11 00:16:14 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-08-11 00:16:14 +0000 |
| commit | d96a8e771ca9f406f0fa1dd4639997335ae444a7 (patch) | |
| tree | 7fbb0ec0b7727e1b43f49076e6bd647ec8b187c1 /lib/CodeGen/CGObjCMac.cpp | |
| parent | f598087b4adfea164acdd5b53ea2951bde740a2d (diff) | |
Fix a bug in @finally emission in both the fragile and non-fragile EH schemes
where we weren't accounting for the possibility that a @finally block might
have internal cleanups and therefore might write to the cleanup destination slot.
Fixes <rdar://problem/8293901>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110760 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGObjCMac.cpp')
| -rw-r--r-- | lib/CodeGen/CGObjCMac.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 3a80330a2f..47e303fb1e 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -2674,11 +2674,22 @@ namespace { if (isa<ObjCAtTryStmt>(S)) { if (const ObjCAtFinallyStmt* FinallyStmt = - cast<ObjCAtTryStmt>(S).getFinallyStmt()) + cast<ObjCAtTryStmt>(S).getFinallyStmt()) { + // Save the current cleanup destination in case there's + // control flow inside the finally statement. + llvm::Value *CurCleanupDest = + CGF.Builder.CreateLoad(CGF.getNormalCleanupDestSlot()); + CGF.EmitStmt(FinallyStmt->getFinallyBody()); - // Currently, the end of the cleanup must always exist. - CGF.EnsureInsertPoint(); + if (CGF.HaveInsertPoint()) { + CGF.Builder.CreateStore(CurCleanupDest, + CGF.getNormalCleanupDestSlot()); + } else { + // Currently, the end of the cleanup must always exist. + CGF.EnsureInsertPoint(); + } + } } else { // Emit objc_sync_exit(expr); as finally's sole statement for // @synchronized. @@ -3030,8 +3041,8 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, llvm::BasicBlock *TryBlock = CGF.createBasicBlock("try"); llvm::BasicBlock *TryHandler = CGF.createBasicBlock("try.handler"); llvm::Value *DidCatch = - CGF.Builder.CreateIsNull(SetJmpResult, "did_catch_exception"); - CGF.Builder.CreateCondBr(DidCatch, TryBlock, TryHandler); + CGF.Builder.CreateIsNotNull(SetJmpResult, "did_catch_exception"); + CGF.Builder.CreateCondBr(DidCatch, TryHandler, TryBlock); // Emit the protected block. CGF.EmitBlock(TryBlock); |
