[cfe-commits] r78445 - /cfe/trunk/lib/CodeGen/CGCXX.cpp
Fariborz Jahanian
fjahanian at apple.com
Fri Aug 7 17:15:41 PDT 2009
Author: fjahanian
Date: Fri Aug 7 19:15:41 2009
New Revision: 78445
URL: http://llvm.org/viewvc/llvm-project?rev=78445&view=rev
Log:
Synthesize copying of non-static data members with
non-trivial copy constructors.
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=78445&r1=78444&r2=78445&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Fri Aug 7 19:15:41 2009
@@ -680,16 +680,16 @@
llvm::Value *Callee = CGM.GetAddrOfCXXConstructor(BaseCopyCtor,
Ctor_Complete);
- llvm::Value *Dest =
- AddressCXXOfBaseClass(DestValue, ClassDecl, BaseClassDecl);
+ llvm::Value *Dest = ClassDecl ?
+ AddressCXXOfBaseClass(DestValue, ClassDecl, BaseClassDecl) : DestValue;
CallArgList CallArgs;
// Push the this (Dest) ptr.
CallArgs.push_back(std::make_pair(RValue::get(Dest),
BaseCopyCtor->getThisType(getContext())));
- llvm::Value *Src =
- AddressCXXOfBaseClass(SrcValue, ClassDecl, BaseClassDecl);
+ llvm::Value *Src = ClassDecl ?
+ AddressCXXOfBaseClass(SrcValue, ClassDecl, BaseClassDecl) : SrcValue;
// Push the Src ptr.
CallArgs.push_back(std::make_pair(RValue::get(Src),
BaseCopyCtor->getThisType(getContext())));
@@ -721,25 +721,45 @@
assert(!ClassDecl->hasUserDeclaredCopyConstructor() &&
"EmitCopyCtorBody - copy constructor has definition already");
+ FunctionArgList::const_iterator i = Args.begin();
+ const VarDecl *ThisArg = i->first;
+ llvm::Value *ThisObj = GetAddrOfLocalVar(ThisArg);
+ llvm::Value *LoadOfThis = Builder.CreateLoad(ThisObj, "this");
+ const VarDecl *SrcArg = (i+1)->first;
+ llvm::Value *SrcObj = GetAddrOfLocalVar(SrcArg);
+ llvm::Value *LoadOfSrc = Builder.CreateLoad(SrcObj);
+
for (CXXRecordDecl::base_class_const_iterator Base = ClassDecl->bases_begin();
Base != ClassDecl->bases_end(); ++Base) {
// FIXME. copy constrution of virtual base NYI
if (Base->isVirtual())
continue;
- FunctionArgList::const_iterator i = Args.begin();
- const VarDecl *ThisArg = i->first;
- llvm::Value *ThisObj = GetAddrOfLocalVar(ThisArg);
- llvm::Value *LoadOfThis = Builder.CreateLoad(ThisObj, "this");
- const VarDecl *SrcArg = (i+1)->first;
- llvm::Value *SrcObj = GetAddrOfLocalVar(SrcArg);
- llvm::Value *LoadOfSrc = Builder.CreateLoad(SrcObj);
-
CXXRecordDecl *BaseClassDecl
= cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
EmitClassMemberwiseCopy(LoadOfThis, LoadOfSrc, ClassDecl, BaseClassDecl);
}
+ for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(),
+ FieldEnd = ClassDecl->field_end();
+ Field != FieldEnd; ++Field) {
+ QualType FieldType = getContext().getCanonicalType((*Field)->getType());
+
+ // FIXME. How about copying arrays!
+ assert(!getContext().getAsArrayType(FieldType) &&
+ "FIXME. Copying arrays NYI");
+
+ if (const RecordType *FieldClassType = FieldType->getAs<RecordType>()) {
+ CXXRecordDecl *FieldClassDecl
+ = cast<CXXRecordDecl>(FieldClassType->getDecl());
+ LValue LHS = EmitLValueForField(LoadOfThis, *Field, false, 0);
+ LValue RHS = EmitLValueForField(LoadOfSrc, *Field, false, 0);
+ EmitClassMemberwiseCopy(LHS.getAddress(), RHS.getAddress(),
+ 0 /*ClassDecl*/, FieldClassDecl);
+ continue;
+ }
+ // FIXME. Do a built-in assignment of scalar data members.
+ }
}
More information about the cfe-commits
mailing list