[PATCH] Don't copy objects with trivial, deleted copy ctors
Reid Kleckner
rnk at google.com
Mon May 12 16:14:28 PDT 2014
OK. I added a two-copy ctor test case, but it's not enough of a corner case. We appear to eagerly declare the implicit special members for it.
PTAL
================
Comment at: lib/CodeGen/CGCXXABI.cpp:49-50
@@ +48,4 @@
+
+ // If all trivial copy and move constructors are deleted, we cannot copy the
+ // argument.
+ return !(AnyDeleted && AllDeleted);
----------------
Richard Smith wrote:
> Please add a FIXME saying that we assume that all lazily-declared trivial copy/move constructors are not deleted, and that this assumption might not actually be true in some corner cases.
done
================
Comment at: lib/CodeGen/ItaniumCXXABI.cpp:65-66
@@ -65,1 +64,4 @@
+ return RAA_Indirect;
+ // If the class has a destructor, the ABI requires us to pass by address.
+ if (RD->hasNonTrivialDestructor())
return RAA_Indirect;
----------------
Richard Smith wrote:
> This should probably be part of the 'canCopy' check; the proposed fix for DR1590 also requires a trivial destructor.
I wasn't thinking about C++11 braced, copyless initialization when I named this. I intended to share it with win64, but those rules are more complicated. I'll fold this in.
================
Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:431-435
@@ +430,7 @@
+
+ // MSVC passes objects with a trivial, non-deleted copy ctor directly.
+ for (const CXXConstructorDecl *CD : RD->ctors()) {
+ if (CD->isCopyConstructor() && CD->isTrivial() && !CD->isDeleted())
+ return RAA_Default;
+ }
+
----------------
Richard Smith wrote:
> As an optimization, you could skip this if `!hasTrivialCopyConstructor()`.
done
http://reviews.llvm.org/D3660
More information about the cfe-commits
mailing list