[cfe-commits] r139143 - in /cfe/trunk: lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CGExprCXX.cpp lib/Sema/SemaDeclCXX.cpp test/CXX/special/class.copy/implicit-move-def.cpp

Douglas Gregor dgregor at apple.com
Tue Sep 6 09:26:56 PDT 2011


Author: dgregor
Date: Tue Sep  6 11:26:56 2011
New Revision: 139143

URL: http://llvm.org/viewvc/llvm-project?rev=139143&view=rev
Log:
When performing a derived-to-base cast on the right-hand side of the
synthesized move assignment within an implicitly-defined move
assignment operator, be sure to treat the derived-to-base cast as an
xvalue (rather than an lvalue). Otherwise, we'll end up getting the
wrong constructor.

Optimize a direct call to a trivial move assignment operator to an
aggregate copy, as we do for trivial copy assignment operators, and
update the the assertion in CodeGenFunction::EmitAggregateCopy() to
cope with this optimization.

Fixes PR10860.


Modified:
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp
    cfe/trunk/lib/CodeGen/CGExprCXX.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/CXX/special/class.copy/implicit-move-def.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=139143&r1=139142&r2=139143&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Tue Sep  6 11:26:56 2011
@@ -1069,7 +1069,9 @@
     if (const RecordType *RT = Ty->getAs<RecordType>()) {
       CXXRecordDecl *Record = cast<CXXRecordDecl>(RT->getDecl());
       assert((Record->hasTrivialCopyConstructor() || 
-              Record->hasTrivialCopyAssignment()) &&
+              Record->hasTrivialCopyAssignment() ||
+              Record->hasTrivialMoveConstructor() ||
+              Record->hasTrivialMoveAssignment()) &&
              "Trying to aggregate-copy a type without a trivial copy "
              "constructor or assignment operator");
       // Ignore empty classes in C++.

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=139143&r1=139142&r2=139143&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Tue Sep  6 11:26:56 2011
@@ -334,16 +334,12 @@
   LValue LV = EmitLValue(E->getArg(0));
   llvm::Value *This = LV.getAddress();
 
-  if (MD->isCopyAssignmentOperator()) {
-    const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(MD->getDeclContext());
-    if (ClassDecl->hasTrivialCopyAssignment()) {
-      assert(!ClassDecl->hasUserDeclaredCopyAssignment() &&
-             "EmitCXXOperatorMemberCallExpr - user declared copy assignment");
-      llvm::Value *Src = EmitLValue(E->getArg(1)).getAddress();
-      QualType Ty = E->getType();
-      EmitAggregateCopy(This, Src, Ty);
-      return RValue::get(This);
-    }
+  if ((MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator()) &&
+      MD->isTrivial()) {
+    llvm::Value *Src = EmitLValue(E->getArg(1)).getAddress();
+    QualType Ty = E->getType();
+    EmitAggregateCopy(This, Src, Ty);
+    return RValue::get(This);
   }
 
   llvm::Value *Callee = EmitCXXOperatorMemberCallee(E, MD, This);

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=139143&r1=139142&r2=139143&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Sep  6 11:26:56 2011
@@ -7847,7 +7847,7 @@
     // appropriately-qualified base type.
     Expr *From = OtherRef;
     From = ImpCastExprToType(From, BaseType, CK_UncheckedDerivedToBase,
-                             VK_RValue, &BasePath).take();
+                             VK_XValue, &BasePath).take();
 
     // Dereference "this".
     ExprResult To = CreateBuiltinUnaryOp(Loc, UO_Deref, This);

Modified: cfe/trunk/test/CXX/special/class.copy/implicit-move-def.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/special/class.copy/implicit-move-def.cpp?rev=139143&r1=139142&r2=139143&view=diff
==============================================================================
--- cfe/trunk/test/CXX/special/class.copy/implicit-move-def.cpp (original)
+++ cfe/trunk/test/CXX/special/class.copy/implicit-move-def.cpp Tue Sep  6 11:26:56 2011
@@ -61,9 +61,25 @@
   unsigned var[1];
 };
 
+// CHECK: define void @_Z1hv() nounwind {
 void h() {
   I i;
+  // CHECK: call void @llvm.memcpy.
   i = I();
+  // CHECK-NEXT: ret void
+}
+
+// PR10860
+struct Empty { };
+struct VirtualWithEmptyBase : Empty {
+  virtual void f();
+};
+
+// CHECK: define void @_Z25move_VirtualWithEmptyBaseR20VirtualWithEmptyBaseS0_
+void move_VirtualWithEmptyBase(VirtualWithEmptyBase &x, VirtualWithEmptyBase &y) {
+  // CHECK: call {{.*}} @_ZN20VirtualWithEmptyBaseaSEOS_
+  x = static_cast<VirtualWithEmptyBase&&>(y);
+  // CHECK-NEXT: ret void
 }
 
 // move assignment ops
@@ -76,8 +92,12 @@
 // CHECK-ASSIGN: br i1
 // CHECK-ASSIGN: call {{.*}} @_ZN1AaSEOS_
 
-// CHECK-ASSIGN: define linkonce_odr {{.*}} @_ZN1IaSEOS_
-// call void @llvm.memcpy.
+// VirtualWithEmptyBase move assignment operatpr
+// CHECK-ASSIGN: define linkonce_odr {{.*}} @_ZN20VirtualWithEmptyBaseaSEOS_
+// CHECK-ASSIGN: store
+// CHECK-ASSIGN-NEXT: store
+// CHECK-NOT: call
+// CHECK: ret
 
 // CHECK-ASSIGN: define linkonce_odr {{.*}} @_ZN1CaSEOS_
 // CHECK-ASSIGN: call {{.*}} @_ZN1AaSEOS_





More information about the cfe-commits mailing list