]> granicus.if.org Git - clang/commitdiff
Handle throw d, where d is a class type but only has a trivial copy
authorMike Stump <mrs@apple.com>
Fri, 20 Nov 2009 01:57:39 +0000 (01:57 +0000)
committerMike Stump <mrs@apple.com>
Fri, 20 Nov 2009 01:57:39 +0000 (01:57 +0000)
constructor.  WIP.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89438 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGException.cpp

index 3abc40775a8ae8e20949681e9f7c62eedf8efa35..fafdf87aabf382dae27690699726453d457f30c0 100644 (file)
@@ -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<CXXRecordDecl>(ThrowType->getAs<RecordType>()->getDecl());
+    if (RD->hasTrivialCopyConstructor()) {
+      EmitAggExpr(E->getSubExpr(), Builder.CreateBitCast(ExceptionPtr, Ty),
+                  false);
+    } else
+      ErrorUnsupported(E, "throw expression with copy ctor");
   }
   
   // Now throw the exception.