[cfe-commits] r92385 - /cfe/trunk/lib/CodeGen/CGException.cpp
Mike Stump
mrs at apple.com
Thu Dec 31 18:51:52 PST 2009
Author: mrs
Date: Thu Dec 31 20:51:52 2009
New Revision: 92385
URL: http://llvm.org/viewvc/llvm-project?rev=92385&view=rev
Log:
Fix catching a reference to a pointer.
Modified:
cfe/trunk/lib/CodeGen/CGException.cpp
Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=92385&r1=92384&r2=92385&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Thu Dec 31 20:51:52 2009
@@ -207,14 +207,21 @@
// 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 @@
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 @@
// 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);
}
More information about the cfe-commits
mailing list