diff options
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGCXX.cpp | 26 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 3 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 6 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 5 |
4 files changed, 40 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp index f161f9f68eb..b65c6b32db7 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/lib/CodeGen/CGCXX.cpp @@ -902,6 +902,32 @@ void CodeGenFunction::SynthesizeCXXCopyConstructor(const CXXConstructorDecl *CD, FinishFunction(); } +/// SynthesizeCXXCopyAssignment - Implicitly define copy assignment operator. +/// Before the implicitly-declared copy assignment operator for a class is +/// implicitly defined, all implicitly- declared copy assignment operators for +/// its direct base classes and its nonstatic data members shall have been +/// implicitly defined. [12.8-p12] +/// The implicitly-defined copy assignment operator for class X performs +/// memberwise assignment of its subob- jects. The direct base classes of X are +/// assigned first, in the order of their declaration in +/// the base-specifier-list, and then the immediate nonstatic data members of X +/// are assigned, in the order in which they were declared in the class +/// definition.Each subobject is assigned in the manner appropriate to its type: +/// — if the subobject is of class type, the copy assignment operator for the +/// class is used (as if by explicit qual- ification; that is, ignoring any +/// possible virtual overriding functions in more derived classes); +/// — if the subobject is an array, each element is assigned, in the manner +/// appropriate to the element type; +/// — if the subobject is of scalar type, the built-in assignment operator is +/// used. +void CodeGenFunction::SynthesizeCXXCopyAssignment(const CXXMethodDecl *CD, + const FunctionDecl *FD, + llvm::Function *Fn, + const FunctionArgList &Args) { + StartFunction(FD, FD->getResultType(), Fn, Args, SourceLocation()); + + FinishFunction(); +} /// EmitCtorPrologue - This routine generates necessary code to initialize /// base classes and non-static data members belonging to this constructor. diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 309c76bea5c..b7ae7c1f0d2 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -254,6 +254,9 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD, SynthesizeDefaultConstructor(CD, FD, Fn, Args); } } + else if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) + if (MD->isCopyAssignment()) + SynthesizeCXXCopyAssignment(MD, FD, Fn, Args); // Destroy the 'this' declaration. if (CXXThisDecl) diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index ece4f105dc2..226c272c318 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -374,6 +374,12 @@ public: const FunctionDecl *FD, llvm::Function *Fn, const FunctionArgList &Args); + + void SynthesizeCXXCopyAssignment(const CXXMethodDecl *CD, + const FunctionDecl *FD, + llvm::Function *Fn, + const FunctionArgList &Args); + void SynthesizeDefaultConstructor(const CXXConstructorDecl *CD, const FunctionDecl *FD, llvm::Function *Fn, diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index a642de9a464..22737a4d933 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -653,6 +653,11 @@ 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); + } } // This function doesn't have a complete type (for example, the return |