[cfe-commits] r78841 - in /cfe/trunk: include/clang/AST/Decl.h lib/CodeGen/CGCXX.cpp lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaDeclCXX.cpp

Fariborz Jahanian fjahanian at apple.com
Wed Aug 12 14:14:36 PDT 2009


Author: fjahanian
Date: Wed Aug 12 16:14:35 2009
New Revision: 78841

URL: http://llvm.org/viewvc/llvm-project?rev=78841&view=rev
Log:
Patch for synthesizing copy assignment operator.
WIP.


Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=78841&r1=78840&r2=78841&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Aug 12 16:14:35 2009
@@ -682,6 +682,7 @@
   bool HasWrittenPrototype : 1;
   bool IsDeleted : 1;
   bool IsTrivial : 1; // sunk from CXXMethodDecl
+  bool IsCopyAssignment : 1;  // sunk from CXXMethodDecl
   bool HasImplicitReturnZero : 1;
 
   // Move to DeclGroup when it is implemented.
@@ -723,6 +724,7 @@
       SClass(S), IsInline(isInline), C99InlineDefinition(false), 
       IsVirtualAsWritten(false), IsPure(false), HasInheritedPrototype(false), 
       HasWrittenPrototype(true), IsDeleted(false), IsTrivial(false),
+      IsCopyAssignment(false),
       HasImplicitReturnZero(false),
       TypeSpecStartLoc(TSSL), EndRangeLoc(L), TemplateOrSpecialization() {}
 
@@ -799,6 +801,9 @@
   /// the class has been fully built by Sema.
   bool isTrivial() const { return IsTrivial; }
   void setTrivial(bool IT) { IsTrivial = IT; }
+                       
+  bool isCopyAssignment() const { return IsCopyAssignment; }
+  void setCopyAssignment(bool CA) { IsCopyAssignment = CA; }
 
   /// Whether falling off this function implicitly returns null/zero.
   /// If a more specific implicit return value is required, front-ends

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=78841&r1=78840&r2=78841&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Wed Aug 12 16:14:35 2009
@@ -902,6 +902,32 @@
   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.

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=78841&r1=78840&r2=78841&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Wed Aug 12 16:14:35 2009
@@ -254,6 +254,9 @@
         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)

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=78841&r1=78840&r2=78841&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Aug 12 16:14:35 2009
@@ -374,6 +374,12 @@
                                     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,

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=78841&r1=78840&r2=78841&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Aug 12 16:14:35 2009
@@ -653,6 +653,11 @@
       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

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=78841&r1=78840&r2=78841&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Aug 12 16:14:35 2009
@@ -1441,6 +1441,7 @@
     CopyAssignment->setAccess(AS_public);
     CopyAssignment->setImplicit();
     CopyAssignment->setTrivial(ClassDecl->hasTrivialCopyAssignment());
+    CopyAssignment->setCopyAssignment(true);
 
     // Add the parameter to the operator.
     ParmVarDecl *FromParam = ParmVarDecl::Create(Context, CopyAssignment,





More information about the cfe-commits mailing list