diff options
author | John McCall <rjmccall@apple.com> | 2010-10-04 23:42:51 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-10-04 23:42:51 +0000 |
commit | 9916e3fa93cf67294892f8b09aba8d13ad389f23 (patch) | |
tree | 616df1f6fc1d21c24f5a807351123052942963d1 /clang/lib | |
parent | bb5f078ce051023a280929d5a745b7ce8843d56b (diff) | |
download | bcm5719-llvm-9916e3fa93cf67294892f8b09aba8d13ad389f23.tar.gz bcm5719-llvm-9916e3fa93cf67294892f8b09aba8d13ad389f23.zip |
In the fragile ObjC ABI, save the caught exception to the side if there are
both @catches and a @finally, because the second call to @objc_exception_try_enter
will clobber the exception slot. Fixes rdar://problem/8440970.
llvm-svn: 115575
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGObjCMac.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index 766703d9e72..c7e4c5ffcf9 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -2973,6 +2973,10 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, llvm::Value *CallTryExitVar = CGF.CreateTempAlloca(CGF.Builder.getInt1Ty(), "_call_try_exit"); + // A slot containing the exception to rethrow. Only needed when we + // have both a @catch and a @finally. + llvm::Value *PropagatingExnVar = 0; + // Push a normal cleanup to leave the try scope. CGF.EHStack.pushCleanup<PerformFragileFinally>(NormalCleanup, &S, SyncArgSlot, @@ -3044,6 +3048,12 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, llvm::BasicBlock *CatchBlock = 0; llvm::BasicBlock *CatchHandler = 0; if (HasFinally) { + // Save the currently-propagating exception before + // objc_exception_try_enter clears the exception slot. + PropagatingExnVar = CGF.CreateTempAlloca(Caught->getType(), + "propagating_exception"); + CGF.Builder.CreateStore(Caught, PropagatingExnVar); + // Enter a new exception try block (in case a @catch block // throws an exception). CGF.Builder.CreateCall(ObjCTypes.getExceptionTryEnterFn(), ExceptionData) @@ -3178,6 +3188,15 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, // the try's write hazard and here. //Hazards.emitWriteHazard(); + // Extract the new exception and save it to the + // propagating-exception slot. + assert(PropagatingExnVar); + llvm::CallInst *NewCaught = + CGF.Builder.CreateCall(ObjCTypes.getExceptionExtractFn(), + ExceptionData, "caught"); + NewCaught->setDoesNotThrow(); + CGF.Builder.CreateStore(NewCaught, PropagatingExnVar); + // Don't pop the catch handler; the throw already did. CGF.Builder.CreateStore(CGF.Builder.getFalse(), CallTryExitVar); CGF.EmitBranchThroughCleanup(FinallyRethrow); @@ -3198,13 +3217,21 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, CGBuilderTy::InsertPoint SavedIP = CGF.Builder.saveAndClearIP(); CGF.EmitBlock(FinallyRethrow.getBlock(), true); if (CGF.HaveInsertPoint()) { - // Just look in the buffer for the exception to throw. - llvm::CallInst *Caught = - CGF.Builder.CreateCall(ObjCTypes.getExceptionExtractFn(), - ExceptionData); - Caught->setDoesNotThrow(); + // If we have a propagating-exception variable, check it. + llvm::Value *PropagatingExn; + if (PropagatingExnVar) { + PropagatingExn = CGF.Builder.CreateLoad(PropagatingExnVar); + + // Otherwise, just look in the buffer for the exception to throw. + } else { + llvm::CallInst *Caught = + CGF.Builder.CreateCall(ObjCTypes.getExceptionExtractFn(), + ExceptionData); + Caught->setDoesNotThrow(); + PropagatingExn = Caught; + } - CGF.Builder.CreateCall(ObjCTypes.getExceptionThrowFn(), Caught) + CGF.Builder.CreateCall(ObjCTypes.getExceptionThrowFn(), PropagatingExn) ->setDoesNotThrow(); CGF.Builder.CreateUnreachable(); } |