[llvm-branch-commits] [llvm] cd2570a - [Support] Remove llvm::is_trivially_{copy/move}_constructible

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jul 27 06:38:15 PDT 2023


Author: Fangrui Song
Date: 2023-07-27T15:29:23+02:00
New Revision: cd2570ae9cdd399e54af029cf1dc51350462d2fd

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

LOG: [Support] Remove llvm::is_trivially_{copy/move}_constructible

This restores D132311, which was reverted in
29c841ce93e087fa4e0c5f3abae94edd460bc24a (Sep 2022) due to certain files
not buildable with GCC 7.3.0. The previous attempt was reverted by
6cd9608fb37ca2418fb44b57ec955bb5efe10689 (Dec 2020).

This time, GCC 7.3.0 has existing build errors for a long time due to
structured bindings for many files, e.g.

```
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:9098:13: error: cannot decompose class type ‘std::pair<llvm::Value*, const llvm::SCEV*>’: both it and it
s base class ‘std::pair<llvm::Value*, const llvm::SCEV*>’ have non-static data members
   for (auto [_, Stride] : Legal->getLAI()->getSymbolicStrides()) {
             ^~~~~~~~~~~
```

... and also some `error: duplicate initialization of` instances due to llvm/Transforms/IPO/Attributor.h.

---

GCC 7.5.0 has a bug that, without this change, certain `SmallVector` with a `std::pair` element type like `SmallVector<std::pair<Instruction * const, Info>, 0> X;` lead to spurious

```
/tmp/opt/gcc-7.5.0/include/c++/7.5.0/type_traits:878:48: error: constructor required before non-static data member for ‘...’ has been parsed
```

Switching to std::is_trivially_{copy/move}_constructible fixes the error.

(cherry picked from commit 6a684dbc4433a33e5f94fb15c9e378a2408021e0)

Added: 
    

Modified: 
    llvm/include/llvm/ADT/FunctionExtras.h
    llvm/include/llvm/ADT/SmallVector.h
    llvm/include/llvm/Support/type_traits.h
    llvm/unittests/Support/TypeTraitsTest.cpp
    mlir/lib/Dialect/SparseTensor/IR/Detail/TemplateExtras.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
index 53de2cb74253a6..4cf1de488c7bde 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<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 CallableT, typename ThisT>
 using EnableUnlessSameType =
@@ -99,11 +99,11 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
   template <typename T> struct AdjustedParamTBase {
     static_assert(!std::is_reference<T>::value,
                   "references should be handled by template specialization");
-    using type = std::conditional_t<
-        llvm::is_trivially_copy_constructible<T>::value &&
-            llvm::is_trivially_move_constructible<T>::value &&
-            IsSizeLessThanThresholdT<T>::value,
-        T, T &>;
+    using type =
+        std::conditional_t<std::is_trivially_copy_constructible<T>::value &&
+                               std::is_trivially_move_constructible<T>::value &&
+                               IsSizeLessThanThresholdT<T>::value,
+                           T, T &>;
   };
 
   // This specialization ensures that 'AdjustedParam<V<T>&>' or

diff  --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 93d94916745d2b..53a107b1574c6a 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -326,8 +326,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> {
   friend class SmallVectorTemplateCommon<T>;

diff  --git a/llvm/include/llvm/Support/type_traits.h b/llvm/include/llvm/Support/type_traits.h
index 86f07c19477d60..3fd158def34d72 100644
--- a/llvm/include/llvm/Support/type_traits.h
+++ b/llvm/include/llvm/Support/type_traits.h
@@ -69,21 +69,6 @@ struct const_pointer_or_const_ref<T, std::enable_if_t<std::is_pointer_v<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;
@@ -91,29 +76,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/TypeTraitsTest.cpp b/llvm/unittests/Support/TypeTraitsTest.cpp
index 229626c778818e..3220cc76351f79 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(llvm::is_trivially_copy_constructible<T>::value ==
+  static_assert(std::is_trivially_copy_constructible<T>::value ==
                     IsTriviallyCopyConstructible,
                 "Mismatch in expected trivial copy construction!");
-  static_assert(llvm::is_trivially_move_constructible<T>::value ==
+  static_assert(std::is_trivially_move_constructible<T>::value ==
                     IsTriviallyMoveConstructible,
                 "Mismatch in expected trivial move construction!");
 

diff  --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/TemplateExtras.h b/mlir/lib/Dialect/SparseTensor/IR/Detail/TemplateExtras.h
index 5c2847dcdf1899..5c222dd966f4f7 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/Detail/TemplateExtras.h
+++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/TemplateExtras.h
@@ -75,8 +75,8 @@ static constexpr bool IsZeroCostAbstraction =
     // use memcpy.  The commentary there mentions that it's intended to be
     // an approximation of `is_trivially_copyable`, so this may be redundant
     // with the above, but we include it just to make sure.
-    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;
 
 //===----------------------------------------------------------------------===//
 


        


More information about the llvm-branch-commits mailing list