Skip to content

Commit cd2570a

Browse files
MaskRaytru
authored andcommitted
[Support] Remove llvm::is_trivially_{copy/move}_constructible
This restores D132311, which was reverted in 29c841c (Sep 2022) due to certain files not buildable with GCC 7.3.0. The previous attempt was reverted by 6cd9608 (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 6a684db)
1 parent 52647ad commit cd2570a

File tree

5 files changed

+12
-50
lines changed

5 files changed

+12
-50
lines changed

llvm/include/llvm/ADT/FunctionExtras.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace detail {
5959

6060
template <typename T>
6161
using EnableIfTrivial =
62-
std::enable_if_t<llvm::is_trivially_move_constructible<T>::value &&
62+
std::enable_if_t<std::is_trivially_move_constructible<T>::value &&
6363
std::is_trivially_destructible<T>::value>;
6464
template <typename CallableT, typename ThisT>
6565
using EnableUnlessSameType =
@@ -99,11 +99,11 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
9999
template <typename T> struct AdjustedParamTBase {
100100
static_assert(!std::is_reference<T>::value,
101101
"references should be handled by template specialization");
102-
using type = std::conditional_t<
103-
llvm::is_trivially_copy_constructible<T>::value &&
104-
llvm::is_trivially_move_constructible<T>::value &&
105-
IsSizeLessThanThresholdT<T>::value,
106-
T, T &>;
102+
using type =
103+
std::conditional_t<std::is_trivially_copy_constructible<T>::value &&
104+
std::is_trivially_move_constructible<T>::value &&
105+
IsSizeLessThanThresholdT<T>::value,
106+
T, T &>;
107107
};
108108

109109
// This specialization ensures that 'AdjustedParam<V<T>&>' or

llvm/include/llvm/ADT/SmallVector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ class SmallVectorTemplateCommon
326326
/// copy these types with memcpy, there is no way for the type to observe this.
327327
/// This catches the important case of std::pair<POD, POD>, which is not
328328
/// trivially assignable.
329-
template <typename T, bool = (is_trivially_copy_constructible<T>::value) &&
330-
(is_trivially_move_constructible<T>::value) &&
329+
template <typename T, bool = (std::is_trivially_copy_constructible<T>::value) &&
330+
(std::is_trivially_move_constructible<T>::value) &&
331331
std::is_trivially_destructible<T>::value>
332332
class SmallVectorTemplateBase : public SmallVectorTemplateCommon<T> {
333333
friend class SmallVectorTemplateCommon<T>;

llvm/include/llvm/Support/type_traits.h

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -69,51 +69,13 @@ struct const_pointer_or_const_ref<T, std::enable_if_t<std::is_pointer_v<T>>> {
6969
};
7070

7171
namespace detail {
72-
/// Internal utility to detect trivial copy construction.
73-
template<typename T> union copy_construction_triviality_helper {
74-
T t;
75-
copy_construction_triviality_helper() = default;
76-
copy_construction_triviality_helper(const copy_construction_triviality_helper&) = default;
77-
~copy_construction_triviality_helper() = default;
78-
};
79-
/// Internal utility to detect trivial move construction.
80-
template<typename T> union move_construction_triviality_helper {
81-
T t;
82-
move_construction_triviality_helper() = default;
83-
move_construction_triviality_helper(move_construction_triviality_helper&&) = default;
84-
~move_construction_triviality_helper() = default;
85-
};
86-
8772
template<class T>
8873
union trivial_helper {
8974
T t;
9075
};
9176

9277
} // end namespace detail
9378

94-
/// An implementation of `std::is_trivially_copy_constructible` since we have
95-
/// users with STLs that don't yet include it.
96-
template <typename T>
97-
struct is_trivially_copy_constructible
98-
: std::is_copy_constructible<
99-
::llvm::detail::copy_construction_triviality_helper<T>> {};
100-
template <typename T>
101-
struct is_trivially_copy_constructible<T &> : std::true_type {};
102-
template <typename T>
103-
struct is_trivially_copy_constructible<T &&> : std::false_type {};
104-
105-
/// An implementation of `std::is_trivially_move_constructible` since we have
106-
/// users with STLs that don't yet include it.
107-
template <typename T>
108-
struct is_trivially_move_constructible
109-
: std::is_move_constructible<
110-
::llvm::detail::move_construction_triviality_helper<T>> {};
111-
template <typename T>
112-
struct is_trivially_move_constructible<T &> : std::true_type {};
113-
template <typename T>
114-
struct is_trivially_move_constructible<T &&> : std::true_type {};
115-
116-
11779
template <typename T>
11880
struct is_copy_assignable {
11981
template<class F>

llvm/unittests/Support/TypeTraitsTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ namespace triviality {
2626
template <typename T, bool IsTriviallyCopyConstructible,
2727
bool IsTriviallyMoveConstructible>
2828
void TrivialityTester() {
29-
static_assert(llvm::is_trivially_copy_constructible<T>::value ==
29+
static_assert(std::is_trivially_copy_constructible<T>::value ==
3030
IsTriviallyCopyConstructible,
3131
"Mismatch in expected trivial copy construction!");
32-
static_assert(llvm::is_trivially_move_constructible<T>::value ==
32+
static_assert(std::is_trivially_move_constructible<T>::value ==
3333
IsTriviallyMoveConstructible,
3434
"Mismatch in expected trivial move construction!");
3535

mlir/lib/Dialect/SparseTensor/IR/Detail/TemplateExtras.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ static constexpr bool IsZeroCostAbstraction =
7575
// use memcpy. The commentary there mentions that it's intended to be
7676
// an approximation of `is_trivially_copyable`, so this may be redundant
7777
// with the above, but we include it just to make sure.
78-
llvm::is_trivially_copy_constructible<T>::value &&
79-
llvm::is_trivially_move_constructible<T>::value;
78+
std::is_trivially_copy_constructible<T>::value &&
79+
std::is_trivially_move_constructible<T>::value;
8080

8181
//===----------------------------------------------------------------------===//
8282

0 commit comments

Comments
 (0)