[cfe-commits] r89442 - /cfe/trunk/lib/CodeGen/CGException.cpp

Mike Stump mrs at apple.com
Thu Nov 19 18:31:07 PST 2009


Author: mrs
Date: Thu Nov 19 20:31:07 2009
New Revision: 89442

URL: http://llvm.org/viewvc/llvm-project?rev=89442&view=rev
Log:
Implement throw d, where d is a class type that requires copy
construction.  WIP.

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=89442&r1=89441&r2=89442&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Thu Nov 19 20:31:07 2009
@@ -88,9 +88,29 @@
     const llvm::Type *Ty = ConvertType(ThrowType)->getPointerTo(0);
     const CXXRecordDecl *RD;
     RD = cast<CXXRecordDecl>(ThrowType->getAs<RecordType>()->getDecl());
+    llvm::Value *This = Builder.CreateBitCast(ExceptionPtr, Ty);
     if (RD->hasTrivialCopyConstructor()) {
-      EmitAggExpr(E->getSubExpr(), Builder.CreateBitCast(ExceptionPtr, Ty),
-                  false);
+      EmitAggExpr(E->getSubExpr(), This, false);
+    } else if (CXXConstructorDecl *CopyCtor
+               = RD->getCopyConstructor(getContext(), 0)) {
+      // FIXME: region management
+      llvm::Value *Src = EmitLValue(E->getSubExpr()).getAddress();
+
+      // Stolen from EmitClassAggrMemberwiseCopy
+      llvm::Value *Callee = CGM.GetAddrOfCXXConstructor(CopyCtor,
+                                                        Ctor_Complete);
+      CallArgList CallArgs;
+      CallArgs.push_back(std::make_pair(RValue::get(This),
+                                        CopyCtor->getThisType(getContext())));
+
+      // Push the Src ptr.
+      CallArgs.push_back(std::make_pair(RValue::get(Src),
+                                        CopyCtor->getParamDecl(0)->getType()));
+      QualType ResultType =
+        CopyCtor->getType()->getAs<FunctionType>()->getResultType();
+      EmitCall(CGM.getTypes().getFunctionInfo(ResultType, CallArgs),
+               Callee, CallArgs, CopyCtor);
+      // FIXME: region management
     } else
       ErrorUnsupported(E, "throw expression with copy ctor");
   }





More information about the cfe-commits mailing list