Author: Mehdi Amini Date: 2020-12-03T19:58:06Z New Revision: 6cd9608fb37ca2418fb44b57ec955bb5efe10689
URL: https://github.com/llvm/llvm-project/commit/6cd9608fb37ca2418fb44b57ec955bb5efe10689 DIFF: https://github.com/llvm/llvm-project/commit/6cd9608fb37ca2418fb44b57ec955bb5efe10689.diff LOG: Revert "Switch to std::is_trivially_move_constructible and std::is_trivially_copy_constructible" This reverts commit c8d406c93c5bb01599990201f78d8428dd29d289. Builds are broken with some versions of GCC. Added: llvm/unittests/Support/TypeTraitsTest.cpp Modified: llvm/include/llvm/ADT/FunctionExtras.h llvm/include/llvm/ADT/SmallVector.h llvm/include/llvm/Support/type_traits.h llvm/unittests/Support/CMakeLists.txt llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn Removed: ################################################################################ diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h index c6ce4eb5c3be..7f8fb103f148 100644 --- a/llvm/include/llvm/ADT/FunctionExtras.h +++ b/llvm/include/llvm/ADT/FunctionExtras.h @@ -57,7 +57,7 @@ namespace detail { template <typename T> using EnableIfTrivial = - std::enable_if_t<std::is_trivially_move_constructible<T>::value && + std::enable_if_t<llvm::is_trivially_move_constructible<T>::value && std::is_trivially_destructible<T>::value>; template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase { @@ -83,8 +83,8 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase { template <typename T> using AdjustedParamT = typename std::conditional< !std::is_reference<T>::value && - std::is_trivially_copy_constructible<T>::value && - std::is_trivially_move_constructible<T>::value && + llvm::is_trivially_copy_constructible<T>::value && + llvm::is_trivially_move_constructible<T>::value && IsSizeLessThanThresholdT<T>::value, T, T &>::type; diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h index f288f4bd106e..c5bb1ece0667 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -278,8 +278,8 @@ class SmallVectorTemplateCommon /// copy these types with memcpy, there is no way for the type to observe this. /// This catches the important case of std::pair<POD, POD>, which is not /// trivially assignable. -template <typename T, bool = (std::is_trivially_copy_constructible<T>::value) && - (std::is_trivially_move_constructible<T>::value) && +template <typename T, bool = (is_trivially_copy_constructible<T>::value) && + (is_trivially_move_constructible<T>::value) && std::is_trivially_destructible<T>::value> class SmallVectorTemplateBase : public SmallVectorTemplateCommon<T> { protected: diff --git a/llvm/include/llvm/Support/type_traits.h b/llvm/include/llvm/Support/type_traits.h index 14d9d06c50ad..7b7d5d991f3f 100644 --- a/llvm/include/llvm/Support/type_traits.h +++ b/llvm/include/llvm/Support/type_traits.h @@ -70,6 +70,20 @@ struct const_pointer_or_const_ref<T, }; namespace detail { +/// Internal utility to detect trivial copy construction. +template<typename T> union copy_construction_triviality_helper { + T t; + copy_construction_triviality_helper() = default; + copy_construction_triviality_helper(const copy_construction_triviality_helper&) = default; + ~copy_construction_triviality_helper() = default; +}; +/// Internal utility to detect trivial move construction. +template<typename T> union move_construction_triviality_helper { + T t; + move_construction_triviality_helper() = default; + move_construction_triviality_helper(move_construction_triviality_helper&&) = default; + ~move_construction_triviality_helper() = default; +}; template<class T> union trivial_helper { @@ -78,6 +92,29 @@ union trivial_helper { } // end namespace detail +/// An implementation of `std::is_trivially_copy_constructible` since we have +/// users with STLs that don't yet include it. +template <typename T> +struct is_trivially_copy_constructible + : std::is_copy_constructible< + ::llvm::detail::copy_construction_triviality_helper<T>> {}; +template <typename T> +struct is_trivially_copy_constructible<T &> : std::true_type {}; +template <typename T> +struct is_trivially_copy_constructible<T &&> : std::false_type {}; + +/// An implementation of `std::is_trivially_move_constructible` since we have +/// users with STLs that don't yet include it. +template <typename T> +struct is_trivially_move_constructible + : std::is_move_constructible< + ::llvm::detail::move_construction_triviality_helper<T>> {}; +template <typename T> +struct is_trivially_move_constructible<T &> : std::true_type {}; +template <typename T> +struct is_trivially_move_constructible<T &&> : std::true_type {}; + + template <typename T> struct is_copy_assignable { template<class F> diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt index 48941b6d4d50..86a25faa7d78 100644 --- a/llvm/unittests/Support/CMakeLists.txt +++ b/llvm/unittests/Support/CMakeLists.txt @@ -80,6 +80,7 @@ add_llvm_unittest(SupportTests TimerTest.cpp ToolOutputFileTest.cpp TypeNameTest.cpp + TypeTraitsTest.cpp TrailingObjectsTest.cpp TrigramIndexTest.cpp UnicodeTest.cpp diff --git a/llvm/unittests/Support/TypeTraitsTest.cpp b/llvm/unittests/Support/TypeTraitsTest.cpp new file mode 100644 index 000000000000..e7a102543e66 --- /dev/null +++ b/llvm/unittests/Support/TypeTraitsTest.cpp @@ -0,0 +1,97 @@ +//===- TypeTraitsTest.cpp -------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/type_traits.h" +#include "gtest/gtest.h" + +namespace { + +// Compile-time tests using static assert. +namespace triviality { + +// Helper for compile time checking trivially copy constructible and trivially +// move constructible type traits. +template <typename T, bool IsTriviallyCopyConstructible, + bool IsTriviallyMoveConstructible> +void TrivialityTester() { + static_assert(llvm::is_trivially_copy_constructible<T>::value == + IsTriviallyCopyConstructible, + "Mismatch in expected trivial copy construction!"); + static_assert(llvm::is_trivially_move_constructible<T>::value == + IsTriviallyMoveConstructible, + "Mismatch in expected trivial move construction!"); + +#if defined(_LIBCPP_VERSION) || defined(_MSC_VER) + // On compilers with support for the standard traits, make sure they agree. + static_assert(std::is_trivially_copy_constructible<T>::value == + IsTriviallyCopyConstructible, + "Mismatch in expected trivial copy construction!"); + static_assert(std::is_trivially_move_constructible<T>::value == + IsTriviallyMoveConstructible, + "Mismatch in expected trivial move construction!"); +#endif +} + +template void TrivialityTester<int, true, true>(); +template void TrivialityTester<void *, true, true>(); +template void TrivialityTester<int &, true, true>(); +template void TrivialityTester<int &&, false, true>(); + +struct X {}; +struct Y { + Y(const Y &); +}; +struct Z { + Z(const Z &); + Z(Z &&); +}; +struct A { + A(const A &) = default; + A(A &&); +}; +struct B { + B(const B &); + B(B &&) = default; +}; + +template void TrivialityTester<X, true, true>(); +template void TrivialityTester<Y, false, false>(); +template void TrivialityTester<Z, false, false>(); +template void TrivialityTester<A, true, false>(); +template void TrivialityTester<B, false, true>(); + +template void TrivialityTester<Z &, true, true>(); +template void TrivialityTester<A &, true, true>(); +template void TrivialityTester<B &, true, true>(); +template void TrivialityTester<Z &&, false, true>(); +template void TrivialityTester<A &&, false, true>(); +template void TrivialityTester<B &&, false, true>(); + +TEST(Triviality, Tester) { + TrivialityTester<int, true, true>(); + TrivialityTester<void *, true, true>(); + TrivialityTester<int &, true, true>(); + TrivialityTester<int &&, false, true>(); + + TrivialityTester<X, true, true>(); + TrivialityTester<Y, false, false>(); + TrivialityTester<Z, false, false>(); + TrivialityTester<A, true, false>(); + TrivialityTester<B, false, true>(); + + TrivialityTester<Z &, true, true>(); + TrivialityTester<A &, true, true>(); + TrivialityTester<B &, true, true>(); + TrivialityTester<Z &&, false, true>(); + TrivialityTester<A &&, false, true>(); + TrivialityTester<B &&, false, true>(); +} + +} // namespace triviality + +} // end anonymous namespace diff --git a/llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn b/llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn index 48ddeb7ed0ec..cd9af3bc20b2 100644 --- a/llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn @@ -85,6 +85,7 @@ unittest("SupportTests") { "TrailingObjectsTest.cpp", "TrigramIndexTest.cpp", "TypeNameTest.cpp", + "TypeTraitsTest.cpp", "UnicodeTest.cpp", "VersionTupleTest.cpp", "VirtualFileSystemTest.cpp", _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits