diff options
author | Serge Guelton <sguelton@redhat.com> | 2019-02-13 09:31:22 +0000 |
---|---|---|
committer | Serge Guelton <sguelton@redhat.com> | 2019-02-13 09:31:22 +0000 |
commit | ab061d351eaa29ca0166b322aacf87d3055c7fde (patch) | |
tree | d3a15c8765b5cf2ebc684cdb8b30f9a435e7d10f /llvm/unittests/ADT | |
parent | da2ed56fea55c2afd3aca5a8261aae2e03675ed7 (diff) | |
download | bcm5719-llvm-ab061d351eaa29ca0166b322aacf87d3055c7fde.tar.gz bcm5719-llvm-ab061d351eaa29ca0166b322aacf87d3055c7fde.zip |
Make llvm::Optional<T> trivially copyable when T is trivially copyable
This is an ever-recurring issue (see https://bugs.llvm.org/show_bug.cgi?id=39427 and https://bugs.llvm.org/show_bug.cgi?id=35978)
but I believe that thanks to https://reviews.llvm.org/D54472 we can now ship a decent implementation of this.
Basically the fact that llvm::is_trivially_copyable has a consistent behavior across compilers should prevent any ABI issue,
and using in-place new instead of memcpy should keep compiler bugs away.
Differential Revision: https://reviews.llvm.org/D57097
llvm-svn: 353927
Diffstat (limited to 'llvm/unittests/ADT')
-rw-r--r-- | llvm/unittests/ADT/OptionalTest.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/OptionalTest.cpp b/llvm/unittests/ADT/OptionalTest.cpp index 9d6d5d29fe0..8d49b3dc22a 100644 --- a/llvm/unittests/ADT/OptionalTest.cpp +++ b/llvm/unittests/ADT/OptionalTest.cpp @@ -16,6 +16,12 @@ using namespace llvm; namespace { +static_assert(llvm::is_trivially_copyable<Optional<int>>::value, + "trivially copyable"); + +static_assert(llvm::is_trivially_copyable<Optional<std::array<int, 3>>>::value, + "trivially copyable"); + struct NonDefaultConstructible { static unsigned CopyConstructions; static unsigned Destructions; @@ -43,6 +49,10 @@ unsigned NonDefaultConstructible::CopyConstructions = 0; unsigned NonDefaultConstructible::Destructions = 0; unsigned NonDefaultConstructible::CopyAssignments = 0; +static_assert( + !llvm::is_trivially_copyable<Optional<NonDefaultConstructible>>::value, + "not trivially copyable"); + // Test fixture class OptionalTest : public testing::Test { }; @@ -201,6 +211,10 @@ struct MultiArgConstructor { }; unsigned MultiArgConstructor::Destructions = 0; +static_assert( + !llvm::is_trivially_copyable<Optional<MultiArgConstructor>>::value, + "not trivially copyable"); + TEST_F(OptionalTest, Emplace) { MultiArgConstructor::ResetCounts(); Optional<MultiArgConstructor> A; @@ -248,6 +262,9 @@ unsigned MoveOnly::MoveConstructions = 0; unsigned MoveOnly::Destructions = 0; unsigned MoveOnly::MoveAssignments = 0; +static_assert(!llvm::is_trivially_copyable<Optional<MoveOnly>>::value, + "not trivially copyable"); + TEST_F(OptionalTest, MoveOnlyNull) { MoveOnly::ResetCounts(); Optional<MoveOnly> O; @@ -349,6 +366,9 @@ private: unsigned Immovable::Constructions = 0; unsigned Immovable::Destructions = 0; +static_assert(!llvm::is_trivially_copyable<Optional<Immovable>>::value, + "not trivially copyable"); + TEST_F(OptionalTest, ImmovableEmplace) { Optional<Immovable> A; Immovable::ResetCounts(); |