aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGException.cpp
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2010-01-01 02:51:52 +0000
committerMike Stump <mrs@apple.com>2010-01-01 02:51:52 +0000
commitb606c384684f317cd75cdb1a2b2b172a42ee7706 (patch)
tree21a77d7bd7336a3c6ade92d93cf4363f513a62c8 /lib/CodeGen/CGException.cpp
parentd203a162966cfc2157857f5fdfb0e30a4f669281 (diff)
Fix catching a reference to a pointer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92385 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGException.cpp')
-rw-r--r--lib/CodeGen/CGException.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp
index 8b37457ccd..8c1a6d28ff 100644
--- a/lib/CodeGen/CGException.cpp
+++ b/lib/CodeGen/CGException.cpp
@@ -207,14 +207,21 @@ static void CopyObject(CodeGenFunction &CGF, const Expr *E,
// CopyObject - Utility to copy an object. Calls copy constructor as necessary.
// N is casted to the right type.
static void CopyObject(CodeGenFunction &CGF, QualType ObjectType,
- bool WasPointer, llvm::Value *E, llvm::Value *N) {
+ bool WasPointer, bool WasReference, llvm::Value *E,
+ llvm::Value *N) {
// Store the throw exception in the exception object.
if (WasPointer || !CGF.hasAggregateLLVMType(ObjectType)) {
llvm::Value *Value = E;
if (!WasPointer)
Value = CGF.Builder.CreateLoad(Value);
const llvm::Type *ValuePtrTy = Value->getType()->getPointerTo(0);
- CGF.Builder.CreateStore(Value, CGF.Builder.CreateBitCast(N, ValuePtrTy));
+ if (WasReference) {
+ llvm::Value *Tmp = CGF.CreateTempAlloca(Value->getType(), "catch.param");
+ CGF.Builder.CreateStore(Value, Tmp);
+ Value = Tmp;
+ } else
+ N = CGF.Builder.CreateBitCast(N, ValuePtrTy);
+ CGF.Builder.CreateStore(Value, N);
} else {
const llvm::Type *Ty = CGF.ConvertType(ObjectType)->getPointerTo(0);
const CXXRecordDecl *RD;
@@ -563,6 +570,10 @@ void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt &S) {
QualType CatchType = CatchParam->getType().getNonReferenceType();
setInvokeDest(TerminateHandler);
bool WasPointer = true;
+ bool WasReference = false;
+ CatchType = CGM.getContext().getCanonicalType(CatchType);
+ if (isa<ReferenceType>(CatchParam->getType()))
+ WasReference = true;
if (!CatchType.getTypePtr()->isPointerType()) {
if (!isa<ReferenceType>(CatchParam->getType()))
WasPointer = false;
@@ -574,7 +585,8 @@ void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt &S) {
// cleanup doesn't start until after the ctor completes, use a decl
// init?
CopyObject(*this, CatchParam->getType().getNonReferenceType(),
- WasPointer, ExcObject, GetAddrOfLocalVar(CatchParam));
+ WasPointer, WasReference, ExcObject,
+ GetAddrOfLocalVar(CatchParam));
setInvokeDest(MatchHandler);
}