]> granicus.if.org Git - clang/commitdiff
Fixed a bug in ir-gen for copy assignment synthesis.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 14 Aug 2009 00:01:54 +0000 (00:01 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 14 Aug 2009 00:01:54 +0000 (00:01 +0000)
Fixed a bug when evaluating those copy-assignments
which need by lazily syntheized. A test case
for these.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78965 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp
lib/CodeGen/CodeGenModule.cpp
test/CodeGenCXX/copy-assign-synthesis-1.cpp [new file with mode: 0644]

index 24e87f521f3d2229d2710cf4eb2e64ac07fea0ca..4460a254b780b6a34dfe7f369eaf929de02f5752 100644 (file)
@@ -1045,7 +1045,10 @@ void CodeGenFunction::SynthesizeCXXCopyAssignment(const CXXMethodDecl *CD,
     LValue RHS = EmitLValueForField(LoadOfSrc, *Field, false, 0);
     RValue RVRHS = EmitLoadOfLValue(RHS, FieldType);
     EmitStoreThroughLValue(RVRHS, LHS, FieldType);
-  }  
+  }
+  
+  // return *this;
+  Builder.CreateStore(LoadOfThis, ReturnValue);
   
   FinishFunction();
 }  
index c9e7e934fd772b0407489541684d1c0f990b6327..6a5700ef19bbf8422b5a353f9c41df1069ff6db9 100644 (file)
@@ -739,7 +739,9 @@ void CodeGenModule::DeferredCopyAssignmentToEmit(GlobalDecl CopyAssignDecl) {
     CXXRecordDecl *BaseClassDecl
       = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
     const CXXMethodDecl *MD = 0;
-    if (BaseClassDecl->hasConstCopyAssignment(getContext(), MD))
+    if (!BaseClassDecl->hasTrivialCopyAssignment() &&
+        !BaseClassDecl->hasUserDeclaredCopyAssignment() &&
+        BaseClassDecl->hasConstCopyAssignment(getContext(), MD))
       GetAddrOfFunction(GlobalDecl(MD), 0);
   }
   
@@ -755,7 +757,9 @@ void CodeGenModule::DeferredCopyAssignmentToEmit(GlobalDecl CopyAssignDecl) {
       CXXRecordDecl *FieldClassDecl
         = cast<CXXRecordDecl>(FieldClassType->getDecl());
       const CXXMethodDecl *MD = 0;
-      if (FieldClassDecl->hasConstCopyAssignment(getContext(), MD))
+      if (!FieldClassDecl->hasTrivialCopyAssignment() &&
+          !FieldClassDecl->hasUserDeclaredCopyAssignment() &&
+          FieldClassDecl->hasConstCopyAssignment(getContext(), MD))
           GetAddrOfFunction(GlobalDecl(MD), 0);
     }
   }
diff --git a/test/CodeGenCXX/copy-assign-synthesis-1.cpp b/test/CodeGenCXX/copy-assign-synthesis-1.cpp
new file mode 100644 (file)
index 0000000..89e3108
--- /dev/null
@@ -0,0 +1,100 @@
+// RUN: clang-cc -triple x86_64-apple-darwin -std=c++0x -S %s -o %t-64.s &&
+// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s &&
+// RUN: clang-cc -triple i386-apple-darwin -std=c++0x -S %s -o %t-32.s &&
+// RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s &&
+// RUN: true
+
+extern "C" int printf(...);
+
+struct B {
+  B() : B1(3.14), B2(3.15), auB2(3.16)  {} 
+  float B1;
+  float B2;
+  void pr() {
+    printf("B1 = %f B2 = %f auB1 = %f\n", B1, B2, auB1);
+  }
+
+  B& operator=(const B& arg) { B1 = arg.B1; B2 = arg.B2; 
+                               auB1 = arg.auB1; return *this; }
+  union {
+    float auB1;
+    float auB2;
+  };
+};
+
+struct M {
+  M() : M1(10), M2(11) , auM1(12) {} 
+  int M1;
+  int M2;
+  void pr() {
+    printf("M1 = %d M2 = %d auM1 = %d auM2 = %d\n", M1, M2, auM1, auM2);
+  }
+  union {
+    int auM1;
+    int auM2;
+  };
+};
+
+struct N  : B {
+  N() : N1(20), N2(21) {} 
+  int N1;
+  int N2;
+  void pr() {
+    printf("N1 = %d N2 = %d\n", N1, N2);
+    B::pr();
+  }
+  N& operator=(const N& arg) { N1 = arg.N1; N2 = arg.N2; 
+                               return *this; }
+};
+
+struct Q  : B {
+  Q() : Q1(30), Q2(31) {} 
+  int Q1;
+  int Q2;
+  void pr() {
+    printf("Q1 = %d Q2 = %d\n", Q1, Q2);
+  }
+};
+
+
+struct X : M , N { 
+  X() : d(0.0), d1(1.1), d2(1.2), d3(1.3) {}
+  double d;
+  double d1;
+  double d2;
+  double d3;
+  void pr() {
+    printf("d = %f d1 = %f d2 = %f d3 = %f\n", d, d1,d2,d3);
+    M::pr(); N::pr();
+    q1.pr(); q2.pr();
+  }
+
+ Q q1, q2;
+}; 
+
+
+X srcX; 
+X dstX; 
+X dstY; 
+
+int main() {
+  dstY = dstX = srcX;
+  srcX.pr();
+  dstX.pr();
+  dstY.pr();
+}
+
+// CHECK-LP64: .globl   __ZN1XaSERK1X
+// CHECK-LP64: .weak_definition  __ZN1XaSERK1X
+// CHECK-LP64: __ZN1XaSERK1X:
+// CHECK-LP64: .globl   __ZN1QaSERK1Q
+// CHECK-LP64: .weak_definition  __ZN1QaSERK1Q
+// CHECK-LP64: __ZN1QaSERK1Q:
+
+// CHECK-LP32: .globl   __ZN1XaSERK1X
+// CHECK-LP32: .weak_definition  __ZN1XaSERK1X
+// CHECK-LP32: __ZN1XaSERK1X:
+// CHECK-LP32: .globl   __ZN1QaSERK1Q
+// CHECK-LP32: .weak_definition  __ZN1QaSERK1Q
+// CHECK-LP32: __ZN1QaSERK1Q:
+