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

Douglas Gregor dgregor at apple.com
Wed Aug 31 19:09:07 PDT 2011


Author: dgregor
Date: Wed Aug 31 21:09:07 2011
New Revision: 138935

URL: http://llvm.org/viewvc/llvm-project?rev=138935&view=rev
Log:
When defining the implicit move assignment operator, don't perform
semantic analysis when taking the address of an xvalue. Instead, just
build the unary operator directly, since it's safe to do so (from the
IRgen and AST perspectives) for any glvalue. Fixes PR10822.

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

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=138935&r1=138934&r2=138935&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Aug 31 21:09:07 2011
@@ -7901,9 +7901,15 @@
         Size *= ArraySize;
       }
 
-      // Take the address of the field references for "from" and "to".
-      From = CreateBuiltinUnaryOp(Loc, UO_AddrOf, From.get());
-      To = CreateBuiltinUnaryOp(Loc, UO_AddrOf, To.get());
+      // Take the address of the field references for "from" and "to". We
+      // directly construct UnaryOperators here because semantic analysis
+      // does not permit us to take the address of an xvalue.
+      From = new (Context) UnaryOperator(From.get(), UO_AddrOf,
+                             Context.getPointerType(From.get()->getType()),
+                             VK_RValue, OK_Ordinary, Loc);
+      To = new (Context) UnaryOperator(To.get(), UO_AddrOf,
+                           Context.getPointerType(To.get()->getType()),
+                           VK_RValue, OK_Ordinary, Loc);
           
       bool NeedsCollectableMemCpy = 
           (BaseType->isRecordType() && 

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=138935&r1=138934&r2=138935&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 Wed Aug 31 21:09:07 2011
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -emit-llvm -o - -std=c++0x %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -o - -std=c++0x %s | FileCheck -check-prefix=CHECK-ASSIGN %s
+// RUN: %clang_cc1 -emit-llvm -o - -std=c++0x %s | FileCheck -check-prefix=CHECK-CTOR %s
 
 // construct
 
@@ -55,30 +56,41 @@
   d = D();
 }
 
+// PR10822
+struct I {
+  unsigned var[1];
+};
+
+void h() {
+  I i;
+  i = I();
+}
 
 // move assignment ops
 
-// CHECK: define linkonce_odr {{.*}} @_ZN1DaSEOS_
-// CHECK: call {{.*}} @_ZN1CaSEOS_
-// CHECK: call {{.*}} @_ZN1AaSEOS_
-// CHECK: call {{.*}} @_ZN1BaSEOS_
+// CHECK-ASSIGN: define linkonce_odr {{.*}} @_ZN1DaSEOS_
+// CHECK-ASSIGN: call {{.*}} @_ZN1CaSEOS_
+// CHECK-ASSIGN: call {{.*}} @_ZN1AaSEOS_
+// CHECK-ASSIGN: call {{.*}} @_ZN1BaSEOS_
 // array loop
-// CHECK: br i1
-// CHECK: call {{.*}} @_ZN1AaSEOS_
+// CHECK-ASSIGN: br i1
+// CHECK-ASSIGN: call {{.*}} @_ZN1AaSEOS_
 
-// CHECK: define linkonce_odr {{.*}} @_ZN1CaSEOS_
-// CHECK: call {{.*}} @_ZN1AaSEOS_
+// CHECK-ASSIGN: define linkonce_odr {{.*}} @_ZN1IaSEOS_
+// call void @llvm.memcpy.
 
+// CHECK-ASSIGN: define linkonce_odr {{.*}} @_ZN1CaSEOS_
+// CHECK-ASSIGN: call {{.*}} @_ZN1AaSEOS_
 
 // move ctors
 
-// CHECK: define linkonce_odr void @_ZN1HC2EOS_
-// CHECK: call void @_ZN1GC2EOS_
-// CHECK: call void @_ZN1FC1EOS_
-// CHECK: call void @_ZN1EC1EOS_
+// CHECK-CTOR: define linkonce_odr void @_ZN1HC2EOS_
+// CHECK-CTOR: call void @_ZN1GC2EOS_
+// CHECK-CTOR: call void @_ZN1FC1EOS_
+// CHECK-CTOR: call void @_ZN1EC1EOS_
 // array loop
-// CHECK: br i1
-// CHECK: call void @_ZN1FC1EOS_
+// CHECK-CTOR: br i1
+// CHECK-CTOR: call void @_ZN1FC1EOS_
 
-// CHECK: define linkonce_odr void @_ZN1GC2EOS_
-// CHECK: call void @_ZN1EC1EOS_
+// CHECK-CTOR: define linkonce_odr void @_ZN1GC2EOS_
+// CHECK-CTOR: call void @_ZN1EC1EOS_





More information about the cfe-commits mailing list