diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-08-13 21:09:41 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-08-13 21:09:41 +0000 |
commit | 4985b33fd7202de05e08e364189a716dead9ec45 (patch) | |
tree | 635472fee4f933fc4d2417a4545a02b31deecb2d /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | df743ae60322bc4c75d5df6213565bc4c9c8b8af (diff) | |
download | bcm5719-llvm-4985b33fd7202de05e08e364189a716dead9ec45.tar.gz bcm5719-llvm-4985b33fd7202de05e08e364189a716dead9ec45.zip |
Patch to force synthesis of copy assignment operator
function in the order according to c++03. ir-gen
for copy assignment in the trivial case and the first
test case.
llvm-svn: 78938
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 22737a4d933..a99bae17995 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -653,11 +653,9 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(const char *MangledName, else if (!ClassDecl->hasUserDeclaredConstructor()) DeferredDeclsToEmit.push_back(D); } - else - if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) - if (MD->isCopyAssignment()) { - DeferredDeclsToEmit.push_back(D); - } + else if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) + if (MD->isCopyAssignment()) + DeferredCopyAssignmentToEmit(D); } // This function doesn't have a complete type (for example, the return @@ -718,7 +716,46 @@ void CodeGenModule::DeferredCopyConstructorToEmit(GlobalDecl CopyCtorDecl) { } } DeferredDeclsToEmit.push_back(CopyCtorDecl); +} + +/// Defer definition of copy assignments which need be implicitly defined. +void CodeGenModule::DeferredCopyAssignmentToEmit(GlobalDecl CopyAssignDecl) { + const CXXMethodDecl *CD = cast<CXXMethodDecl>(CopyAssignDecl.getDecl()); + const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(CD->getDeclContext()); + if (ClassDecl->hasTrivialCopyAssignment() || + ClassDecl->hasUserDeclaredCopyAssignment()) + return; + + // First make sure all direct base classes and virtual bases and non-static + // data mebers which need to have their copy assignments implicitly defined + // are defined. 12.8.p12 + for (CXXRecordDecl::base_class_const_iterator Base = ClassDecl->bases_begin(); + Base != ClassDecl->bases_end(); ++Base) { + CXXRecordDecl *BaseClassDecl + = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); + const CXXMethodDecl *MD = 0; + if (BaseClassDecl->hasConstCopyAssignment(getContext(), MD)) + GetAddrOfFunction(GlobalDecl(MD), 0); + } + + for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(), + FieldEnd = ClassDecl->field_end(); + Field != FieldEnd; ++Field) { + QualType FieldType = Context.getCanonicalType((*Field)->getType()); + if (const ArrayType *Array = Context.getAsArrayType(FieldType)) + FieldType = Array->getElementType(); + if (const RecordType *FieldClassType = FieldType->getAs<RecordType>()) { + if ((*Field)->isAnonymousStructOrUnion()) + continue; + CXXRecordDecl *FieldClassDecl + = cast<CXXRecordDecl>(FieldClassType->getDecl()); + const CXXMethodDecl *MD = 0; + if (FieldClassDecl->hasConstCopyAssignment(getContext(), MD)) + GetAddrOfFunction(GlobalDecl(MD), 0); + } + } + DeferredDeclsToEmit.push_back(CopyAssignDecl); } /// GetAddrOfFunction - Return the address of the given function. If Ty is |