diff options
author | Anders Carlsson <andersca@mac.com> | 2009-12-11 00:32:37 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-12-11 00:32:37 +0000 |
commit | 8370c58b9295b32bee50443fe3ac43a47a2047e8 (patch) | |
tree | 684eab922ccb9658aa430d9992f6d22aed54fcb5 /lib/CodeGen/CGException.cpp | |
parent | 5c2609a1f9c68bbbb3dc665df212988133e85439 (diff) |
When an exception needs to be freed by calling __cxa_exception_free, make sure to stash away the exception pointer somewhere.
This fixes an "Instruction does not dominate all uses!" verification error when compiling TableGen.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91084 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGException.cpp')
-rw-r--r-- | lib/CodeGen/CGException.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp index b460fa9be0..07e7546637 100644 --- a/lib/CodeGen/CGException.cpp +++ b/lib/CodeGen/CGException.cpp @@ -127,21 +127,24 @@ static llvm::Constant *getTerminateFn(CodeGenFunction &CGF) { } // CopyObject - Utility to copy an object. Calls copy constructor as necessary. -// N is casted to the right type. -static void CopyObject(CodeGenFunction &CGF, const Expr *E, llvm::Value *N) { +// DestPtr is casted to the right type. +static void CopyObject(CodeGenFunction &CGF, const Expr *E, + llvm::Value *DestPtr, llvm::Value *ExceptionPtrPtr) { QualType ObjectType = E->getType(); // Store the throw exception in the exception object. if (!CGF.hasAggregateLLVMType(ObjectType)) { llvm::Value *Value = CGF.EmitScalarExpr(E); - const llvm::Type *ValuePtrTy = Value->getType()->getPointerTo(0); + const llvm::Type *ValuePtrTy = Value->getType()->getPointerTo(); - CGF.Builder.CreateStore(Value, CGF.Builder.CreateBitCast(N, ValuePtrTy)); + CGF.Builder.CreateStore(Value, + CGF.Builder.CreateBitCast(DestPtr, ValuePtrTy)); } else { - const llvm::Type *Ty = CGF.ConvertType(ObjectType)->getPointerTo(0); - const CXXRecordDecl *RD; - RD = cast<CXXRecordDecl>(ObjectType->getAs<RecordType>()->getDecl()); - llvm::Value *This = CGF.Builder.CreateBitCast(N, Ty); + const llvm::Type *Ty = CGF.ConvertType(ObjectType)->getPointerTo(); + const CXXRecordDecl *RD = + cast<CXXRecordDecl>(ObjectType->getAs<RecordType>()->getDecl()); + + llvm::Value *This = CGF.Builder.CreateBitCast(DestPtr, Ty); if (RD->hasTrivialCopyConstructor()) { CGF.EmitAggExpr(E, This, false); } else if (CXXConstructorDecl *CopyCtor @@ -150,9 +153,9 @@ static void CopyObject(CodeGenFunction &CGF, const Expr *E, llvm::Value *N) { if (CGF.Exceptions) { CodeGenFunction::EHCleanupBlock Cleanup(CGF); llvm::Constant *FreeExceptionFn = getFreeExceptionFn(CGF); - const llvm::Type *Int8PtrTy - = llvm::Type::getInt8PtrTy(CGF.getLLVMContext()); - llvm::Value *ExceptionPtr = CGF.Builder.CreateBitCast(N, Int8PtrTy); + + // Load the exception pointer. + llvm::Value *ExceptionPtr = CGF.Builder.CreateLoad(ExceptionPtrPtr); CGF.Builder.CreateCall(FreeExceptionFn, ExceptionPtr); } @@ -251,8 +254,13 @@ void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E) { Builder.CreateCall(AllocExceptionFn, llvm::ConstantInt::get(SizeTy, TypeSize), "exception"); + + llvm::Value *ExceptionPtrPtr = + CreateTempAlloca(ExceptionPtr->getType(), "exception.ptr"); + Builder.CreateStore(ExceptionPtr, ExceptionPtrPtr); + - CopyObject(*this, E->getSubExpr(), ExceptionPtr); + CopyObject(*this, E->getSubExpr(), ExceptionPtr, ExceptionPtrPtr); // Now throw the exception. const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(getLLVMContext()); |