[cfe-commits] r90823 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/copy-assign-synthesis-3.cpp
Eli Friedman
eli.friedman at gmail.com
Mon Dec 7 17:57:54 PST 2009
Author: efriedma
Date: Mon Dec 7 19:57:53 2009
New Revision: 90823
URL: http://llvm.org/viewvc/llvm-project?rev=90823&view=rev
Log:
Make copy assignment operator synthesis not explode for classes with complex
or non-record aggregate members.
It might be worth spending some time to optimize this code (and the parallel
code for copy constructors) to memcpy in larger chunks, rather than copying
one member at a time. Not sure exactly how beneficial that would be, but
it seems like could help for large classes with, for example, a vtable pointer
forcing the generation of a copy constructor.
Added:
cfe/trunk/test/CodeGenCXX/copy-assign-synthesis-3.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=90823&r1=90822&r2=90823&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Mon Dec 7 19:57:53 2009
@@ -1655,8 +1655,16 @@
// Do a built-in assignment of scalar data members.
LValue LHS = EmitLValueForField(LoadOfThis, *Field, false, 0);
LValue RHS = EmitLValueForField(LoadOfSrc, *Field, false, 0);
- RValue RVRHS = EmitLoadOfLValue(RHS, FieldType);
- EmitStoreThroughLValue(RVRHS, LHS, FieldType);
+ if (!hasAggregateLLVMType(Field->getType())) {
+ RValue RVRHS = EmitLoadOfLValue(RHS, Field->getType());
+ EmitStoreThroughLValue(RVRHS, LHS, Field->getType());
+ } else if (Field->getType()->isAnyComplexType()) {
+ ComplexPairTy Pair = LoadComplexFromAddr(RHS.getAddress(),
+ RHS.isVolatileQualified());
+ StoreComplexToAddr(Pair, LHS.getAddress(), LHS.isVolatileQualified());
+ } else {
+ EmitAggregateCopy(LHS.getAddress(), RHS.getAddress(), Field->getType());
+ }
}
// return *this;
Added: cfe/trunk/test/CodeGenCXX/copy-assign-synthesis-3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/copy-assign-synthesis-3.cpp?rev=90823&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/copy-assign-synthesis-3.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/copy-assign-synthesis-3.cpp Mon Dec 7 19:57:53 2009
@@ -0,0 +1,16 @@
+// RUN: clang-cc -emit-llvm-only -verify %s
+
+struct A {
+ A& operator=(const A&);
+};
+
+struct B {
+ A a;
+ float b;
+ int (A::*c)();
+ _Complex float d;
+};
+void a(B& x, B& y) {
+ x = y;
+}
+
More information about the cfe-commits
mailing list