diff options
| author | Reid Kleckner <reid@kleckner.net> | 2014-05-14 16:02:09 +0000 |
|---|---|---|
| committer | Reid Kleckner <reid@kleckner.net> | 2014-05-14 16:02:09 +0000 |
| commit | 13ec00d6d7dbed25cfdc202ca482de2ecb41c61b (patch) | |
| tree | 0a3996a3fd9ef1d617d3aa5fbb61ba4655123789 /lib/CodeGen/ItaniumCXXABI.cpp | |
| parent | b51314cc3e1eb7bd67a27fb1a8410b01cf4c6895 (diff) | |
| download | clang-13ec00d6d7dbed25cfdc202ca482de2ecb41c61b.tar.gz clang-13ec00d6d7dbed25cfdc202ca482de2ecb41c61b.tar.bz2 clang-13ec00d6d7dbed25cfdc202ca482de2ecb41c61b.tar.xz | |
Don't copy objects with trivial, deleted copy ctors
This affects both the Itanium and Microsoft C++ ABIs.
This is in anticipation of a change to the Itanium C++ ABI, and should
match GCC's current behavior. The new text will likely be:
"""
Pass an object of class type by value if every copy constructor and
move constructor is deleted or trivial and at least one of them is not
deleted, and the destructor is trivial.
"""
http://sourcerytools.com/pipermail/cxx-abi-dev/2014-May/002728.html
On x86 Windows, we can mostly use the same logic, where we use inalloca
instead of passing by address. However, on Win64, there are register
parameters, and we have to do what MSVC does. MSVC ignores the presence
of non-trivial move constructors and only considers the presence of
non-trivial or deleted copy constructors. If a non-trivial or deleted
copy ctor is present, it passes the argument indirectly.
This change fixes bugs and makes us more ABI compatible with both GCC
and MSVC.
Fixes PR19668.
Reviewers: rsmith
Differential Revision: http://reviews.llvm.org/D3660
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208786 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/ItaniumCXXABI.cpp')
| -rw-r--r-- | lib/CodeGen/ItaniumCXXABI.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp index 201a753477..e3605e1b9c 100644 --- a/lib/CodeGen/ItaniumCXXABI.cpp +++ b/lib/CodeGen/ItaniumCXXABI.cpp @@ -55,9 +55,8 @@ public: bool classifyReturnType(CGFunctionInfo &FI) const override; RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const override { - // Structures with either a non-trivial destructor or a non-trivial - // copy constructor are always indirect. - if (!RD->hasTrivialDestructor() || RD->hasNonTrivialCopyConstructor()) + // If C++ prohibits us from making a copy, pass by address. + if (!canCopyArgument(RD)) return RAA_Indirect; return RAA_Default; } @@ -762,13 +761,11 @@ bool ItaniumCXXABI::classifyReturnType(CGFunctionInfo &FI) const { if (!RD) return false; - // Return indirectly if we have a non-trivial copy ctor or non-trivial dtor. - if (RD->hasNonTrivialDestructor() || RD->hasNonTrivialCopyConstructor()) { + // If C++ prohibits us from making a copy, return by address. + if (!canCopyArgument(RD)) { FI.getReturnInfo() = ABIArgInfo::getIndirect(0, /*ByVal=*/false); return true; } - - // Otherwise, use the normal C ABI rules. return false; } |
