[llvm] 29c841c - Revert "[llvm] Remove llvm::is_trivially_{copy/move}_constructible (NFC)"

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 16 18:26:29 PDT 2022


Author: Kazu Hirata
Date: 2022-09-16T18:26:20-07:00
New Revision: 29c841ce93e087fa4e0c5f3abae94edd460bc24a

URL: https://github.com/llvm/llvm-project/commit/29c841ce93e087fa4e0c5f3abae94edd460bc24a
DIFF: https://github.com/llvm/llvm-project/commit/29c841ce93e087fa4e0c5f3abae94edd460bc24a.diff

LOG: Revert "[llvm] Remove llvm::is_trivially_{copy/move}_constructible (NFC)"

This reverts commit 01ffe31cbb54bfd8e38e71b3cf804a1d67ebf9c1.

A build breakage with GCC 7.3 has been reported:

https://reviews.llvm.org/D132311#3797053

FWIW, GCC 7.5 is OK according to Pavel Chupin.  I also personally
tested GCC 8.4.0.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/FunctionExtras.h
    llvm/include/llvm/ADT/Optional.h
    llvm/include/llvm/ADT/SmallVector.h
    llvm/include/llvm/Support/type_traits.h
    llvm/unittests/Support/TypeTraitsTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
index a694e0ecfc779..35e160fc63ad5 100644
--- a/llvm/include/llvm/ADT/FunctionExtras.h
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
@@ -59,7 +59,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 CallableT, typename ThisT>
 using EnableUnlessSameType =
@@ -100,8 +100,8 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
     static_assert(!std::is_reference<T>::value,
                   "references should be handled by template specialization");
     using type = typename std::conditional<
-        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/Optional.h b/llvm/include/llvm/ADT/Optional.h
index 3ff591d6a1772..0f4e500834855 100644
--- a/llvm/include/llvm/ADT/Optional.h
+++ b/llvm/include/llvm/ADT/Optional.h
@@ -50,12 +50,13 @@ namespace optional_detail {
 //
 // The move constructible / assignable conditions emulate the remaining behavior
 // of std::is_trivially_copyable.
-template <typename T, bool = (std::is_trivially_copy_constructible<T>::value &&
-                              std::is_trivially_copy_assignable<T>::value &&
-                              (std::is_trivially_move_constructible<T>::value ||
-                               !std::is_move_constructible<T>::value) &&
-                              (std::is_trivially_move_assignable<T>::value ||
-                               !std::is_move_assignable<T>::value))>
+template <typename T,
+          bool = (llvm::is_trivially_copy_constructible<T>::value &&
+                  std::is_trivially_copy_assignable<T>::value &&
+                  (llvm::is_trivially_move_constructible<T>::value ||
+                   !std::is_move_constructible<T>::value) &&
+                  (std::is_trivially_move_assignable<T>::value ||
+                   !std::is_move_assignable<T>::value))>
 class OptionalStorage {
   union {
     char empty;

diff  --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 7770e3b5b1992..14f051e383f72 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -312,8 +312,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> {
   friend class SmallVectorTemplateCommon<T>;

diff  --git a/llvm/include/llvm/Support/type_traits.h b/llvm/include/llvm/Support/type_traits.h
index 3a9169beeb5f4..a6046de87d1e3 100644
--- a/llvm/include/llvm/Support/type_traits.h
+++ b/llvm/include/llvm/Support/type_traits.h
@@ -70,6 +70,21 @@ 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 {
     T t;
@@ -77,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/TypeTraitsTest.cpp b/llvm/unittests/Support/TypeTraitsTest.cpp
index a7adce9f8f248..734e50afa2db3 100644
--- a/llvm/unittests/Support/TypeTraitsTest.cpp
+++ b/llvm/unittests/Support/TypeTraitsTest.cpp
@@ -26,10 +26,10 @@ namespace triviality {
 template <typename T, bool IsTriviallyCopyConstructible,
           bool IsTriviallyMoveConstructible>
 void TrivialityTester() {
-  static_assert(std::is_trivially_copy_constructible<T>::value ==
+  static_assert(llvm::is_trivially_copy_constructible<T>::value ==
                     IsTriviallyCopyConstructible,
                 "Mismatch in expected trivial copy construction!");
-  static_assert(std::is_trivially_move_constructible<T>::value ==
+  static_assert(llvm::is_trivially_move_constructible<T>::value ==
                     IsTriviallyMoveConstructible,
                 "Mismatch in expected trivial move construction!");
 


        


More information about the llvm-commits mailing list