From: Mike Stump Date: Fri, 20 Nov 2009 01:57:39 +0000 (+0000) Subject: Handle throw d, where d is a class type but only has a trivial copy X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e36c9abd383267775a5079166e5e02119866c129;p=clang Handle throw d, where d is a class type but only has a trivial copy constructor. WIP. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89438 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp index 3abc40775a..fafdf87aab 100644 --- a/lib/CodeGen/CGException.cpp +++ b/lib/CodeGen/CGException.cpp @@ -61,12 +61,6 @@ void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E) { } QualType ThrowType = E->getSubExpr()->getType(); - // FIXME: We only handle non-class types for now. - if (ThrowType->isRecordType()) { - ErrorUnsupported(E, "throw expression"); - return; - } - // FIXME: Handle cleanup. if (!CleanupEntries.empty()){ ErrorUnsupported(E, "throw expression"); @@ -90,8 +84,15 @@ void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E) { Builder.CreateStore(Value, Builder.CreateBitCast(ExceptionPtr, ValuePtrTy)); } else { - // FIXME: Handle complex and aggregate expressions. - ErrorUnsupported(E, "throw expression"); + // See EmitCXXConstructorCall. + const llvm::Type *Ty = ConvertType(ThrowType)->getPointerTo(0); + const CXXRecordDecl *RD; + RD = cast(ThrowType->getAs()->getDecl()); + if (RD->hasTrivialCopyConstructor()) { + EmitAggExpr(E->getSubExpr(), Builder.CreateBitCast(ExceptionPtr, Ty), + false); + } else + ErrorUnsupported(E, "throw expression with copy ctor"); } // Now throw the exception.