aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGException.cpp
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2009-12-02 23:37:16 +0000
committerMike Stump <mrs@apple.com>2009-12-02 23:37:16 +0000
commitf7f74675d4e63c4529a4b890c0dd62cf6dc4c476 (patch)
tree981b5ef3c30643ac25b9427050e4089e0fc531a5 /lib/CodeGen/CGException.cpp
parent730203088e9909e304c4868cbca72ee2652335bf (diff)
Add a cleanup scope for each catch clause.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90357 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGException.cpp')
-rw-r--r--lib/CodeGen/CGException.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp
index f4d235c8e6..02bc05a68e 100644
--- a/lib/CodeGen/CGException.cpp
+++ b/lib/CodeGen/CGException.cpp
@@ -381,29 +381,33 @@ void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt &S) {
llvm::Value *ExcObject = Builder.CreateCall(getBeginCatchFn(*this), Exc);
- // Bind the catch parameter if it exists.
- if (CatchParam) {
- QualType CatchType = CatchParam->getType().getNonReferenceType();
- setInvokeDest(TerminateHandler);
- if (!CatchType.getTypePtr()->isPointerType())
- CatchType = getContext().getPointerType(CatchType);
- ExcObject =
- Builder.CreateBitCast(ExcObject, ConvertType(CatchType));
+ {
+ CleanupScope CatchScope(*this);
+ // Bind the catch parameter if it exists.
+ if (CatchParam) {
+ QualType CatchType = CatchParam->getType().getNonReferenceType();
+ setInvokeDest(TerminateHandler);
+ if (!CatchType.getTypePtr()->isPointerType())
+ CatchType = getContext().getPointerType(CatchType);
+ ExcObject = Builder.CreateBitCast(ExcObject, ConvertType(CatchType));
// CatchParam is a ParmVarDecl because of the grammar
// construction used to handle this, but for codegen purposes
// we treat this as a local decl.
- EmitLocalBlockVarDecl(*CatchParam);
+ EmitLocalBlockVarDecl(*CatchParam);
#if 0
- // FIXME: objects with ctors, references
- Builder.CreateStore(ExcObject, GetAddrOfLocalVar(CatchParam));
+ // FIXME: objects with ctors, references
+ Builder.CreateStore(ExcObject, GetAddrOfLocalVar(CatchParam));
#else
- CopyObject(*this, CatchParam->getType().getNonReferenceType(),
- ExcObject, GetAddrOfLocalVar(CatchParam));
+ // FIXME: we need to do this sooner so that the EH region for the cleanup doesn't start until after the ctor completes, use a decl init?
+ CopyObject(*this, CatchParam->getType().getNonReferenceType(),
+ ExcObject, GetAddrOfLocalVar(CatchParam));
#endif
- setInvokeDest(MatchHandler);
+ setInvokeDest(MatchHandler);
+ }
+
+ EmitStmt(CatchBody);
}
- EmitStmt(CatchBody);
EmitBranchThroughCleanup(FinallyEnd);
EmitBlock(MatchHandler);