Author: Fangrui Song Date: 2020-12-03T09:15:40-08:00 New Revision: c8d406c93c5bb01599990201f78d8428dd29d289
URL: https://github.com/llvm/llvm-project/commit/c8d406c93c5bb01599990201f78d8428dd29d289 DIFF: https://github.com/llvm/llvm-project/commit/c8d406c93c5bb01599990201f78d8428dd29d289.diff LOG: Switch to std::is_trivially_move_constructible and std::is_trivially_copy_constructible Differential Revision: https://reviews.llvm.org/D92543 Added: 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: llvm/unittests/Support/TypeTraitsTest.cpp ################################################################################ diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h index 7f8fb103f148..c6ce4eb5c3be 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<llvm::is_trivially_move_constructible<T>::value && + std::enable_if_t<std::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 && - llvm::is_trivially_copy_constructible<T>::value && - llvm::is_trivially_move_constructible<T>::value && + std::is_trivially_copy_constructible<T>::value && + std::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 c5bb1ece0667..f288f4bd106e 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 = (is_trivially_copy_constructible<T>::value) && - (is_trivially_move_constructible<T>::value) && +template <typename T, bool = (std::is_trivially_copy_constructible<T>::value) && + (std::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 7b7d5d991f3f..14d9d06c50ad 100644 --- a/llvm/include/llvm/Support/type_traits.h +++ b/llvm/include/llvm/Support/type_traits.h @@ -70,20 +70,6 @@ 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 { @@ -92,29 +78,6 @@ 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 86a25faa7d78..48941b6d4d50 100644 --- a/llvm/unittests/Support/CMakeLists.txt +++ b/llvm/unittests/Support/CMakeLists.txt @@ -80,7 +80,6 @@ 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 deleted file mode 100644 index e7a102543e66..000000000000 --- a/llvm/unittests/Support/TypeTraitsTest.cpp +++ /dev/null @@ -1,97 +0,0 @@ -//===- 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 cd9af3bc20b2..48ddeb7ed0ec 100644 --- a/llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn @@ -85,7 +85,6 @@ 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