Skip to content

Commit 6cd9608

Browse files
committed
Revert "Switch to std::is_trivially_move_constructible and std::is_trivially_copy_constructible"
This reverts commit c8d406c. Builds are broken with some versions of GCC.
1 parent f6b9afa commit 6cd9608

File tree

6 files changed

+141
-5
lines changed

6 files changed

+141
-5
lines changed

llvm/include/llvm/ADT/FunctionExtras.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace detail {
5757

5858
template <typename T>
5959
using EnableIfTrivial =
60-
std::enable_if_t<std::is_trivially_move_constructible<T>::value &&
60+
std::enable_if_t<llvm::is_trivially_move_constructible<T>::value &&
6161
std::is_trivially_destructible<T>::value>;
6262

6363
template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
@@ -83,8 +83,8 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
8383
template <typename T>
8484
using AdjustedParamT = typename std::conditional<
8585
!std::is_reference<T>::value &&
86-
std::is_trivially_copy_constructible<T>::value &&
87-
std::is_trivially_move_constructible<T>::value &&
86+
llvm::is_trivially_copy_constructible<T>::value &&
87+
llvm::is_trivially_move_constructible<T>::value &&
8888
IsSizeLessThanThresholdT<T>::value,
8989
T, T &>::type;
9090

llvm/include/llvm/ADT/SmallVector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ class SmallVectorTemplateCommon
278278
/// copy these types with memcpy, there is no way for the type to observe this.
279279
/// This catches the important case of std::pair<POD, POD>, which is not
280280
/// trivially assignable.
281-
template <typename T, bool = (std::is_trivially_copy_constructible<T>::value) &&
282-
(std::is_trivially_move_constructible<T>::value) &&
281+
template <typename T, bool = (is_trivially_copy_constructible<T>::value) &&
282+
(is_trivially_move_constructible<T>::value) &&
283283
std::is_trivially_destructible<T>::value>
284284
class SmallVectorTemplateBase : public SmallVectorTemplateCommon<T> {
285285
protected:

llvm/include/llvm/Support/type_traits.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ struct const_pointer_or_const_ref<T,
7070
};
7171

7272
namespace detail {
73+
/// Internal utility to detect trivial copy construction.
74+
template<typename T> union copy_construction_triviality_helper {
75+
T t;
76+
copy_construction_triviality_helper() = default;
77+
copy_construction_triviality_helper(const copy_construction_triviality_helper&) = default;
78+
~copy_construction_triviality_helper() = default;
79+
};
80+
/// Internal utility to detect trivial move construction.
81+
template<typename T> union move_construction_triviality_helper {
82+
T t;
83+
move_construction_triviality_helper() = default;
84+
move_construction_triviality_helper(move_construction_triviality_helper&&) = default;
85+
~move_construction_triviality_helper() = default;
86+
};
7387

7488
template<class T>
7589
union trivial_helper {
@@ -78,6 +92,29 @@ union trivial_helper {
7892

7993
} // end namespace detail
8094

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

llvm/unittests/Support/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ add_llvm_unittest(SupportTests
8080
TimerTest.cpp
8181
ToolOutputFileTest.cpp
8282
TypeNameTest.cpp
83+
TypeTraitsTest.cpp
8384
TrailingObjectsTest.cpp
8485
TrigramIndexTest.cpp
8586
UnicodeTest.cpp
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//===- TypeTraitsTest.cpp -------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "llvm/Support/type_traits.h"
10+
#include "gtest/gtest.h"
11+
12+
namespace {
13+
14+
// Compile-time tests using static assert.
15+
namespace triviality {
16+
17+
// Helper for compile time checking trivially copy constructible and trivially
18+
// move constructible type traits.
19+
template <typename T, bool IsTriviallyCopyConstructible,
20+
bool IsTriviallyMoveConstructible>
21+
void TrivialityTester() {
22+
static_assert(llvm::is_trivially_copy_constructible<T>::value ==
23+
IsTriviallyCopyConstructible,
24+
"Mismatch in expected trivial copy construction!");
25+
static_assert(llvm::is_trivially_move_constructible<T>::value ==
26+
IsTriviallyMoveConstructible,
27+
"Mismatch in expected trivial move construction!");
28+
29+
#if defined(_LIBCPP_VERSION) || defined(_MSC_VER)
30+
// On compilers with support for the standard traits, make sure they agree.
31+
static_assert(std::is_trivially_copy_constructible<T>::value ==
32+
IsTriviallyCopyConstructible,
33+
"Mismatch in expected trivial copy construction!");
34+
static_assert(std::is_trivially_move_constructible<T>::value ==
35+
IsTriviallyMoveConstructible,
36+
"Mismatch in expected trivial move construction!");
37+
#endif
38+
}
39+
40+
template void TrivialityTester<int, true, true>();
41+
template void TrivialityTester<void *, true, true>();
42+
template void TrivialityTester<int &, true, true>();
43+
template void TrivialityTester<int &&, false, true>();
44+
45+
struct X {};
46+
struct Y {
47+
Y(const Y &);
48+
};
49+
struct Z {
50+
Z(const Z &);
51+
Z(Z &&);
52+
};
53+
struct A {
54+
A(const A &) = default;
55+
A(A &&);
56+
};
57+
struct B {
58+
B(const B &);
59+
B(B &&) = default;
60+
};
61+
62+
template void TrivialityTester<X, true, true>();
63+
template void TrivialityTester<Y, false, false>();
64+
template void TrivialityTester<Z, false, false>();
65+
template void TrivialityTester<A, true, false>();
66+
template void TrivialityTester<B, false, true>();
67+
68+
template void TrivialityTester<Z &, true, true>();
69+
template void TrivialityTester<A &, true, true>();
70+
template void TrivialityTester<B &, true, true>();
71+
template void TrivialityTester<Z &&, false, true>();
72+
template void TrivialityTester<A &&, false, true>();
73+
template void TrivialityTester<B &&, false, true>();
74+
75+
TEST(Triviality, Tester) {
76+
TrivialityTester<int, true, true>();
77+
TrivialityTester<void *, true, true>();
78+
TrivialityTester<int &, true, true>();
79+
TrivialityTester<int &&, false, true>();
80+
81+
TrivialityTester<X, true, true>();
82+
TrivialityTester<Y, false, false>();
83+
TrivialityTester<Z, false, false>();
84+
TrivialityTester<A, true, false>();
85+
TrivialityTester<B, false, true>();
86+
87+
TrivialityTester<Z &, true, true>();
88+
TrivialityTester<A &, true, true>();
89+
TrivialityTester<B &, true, true>();
90+
TrivialityTester<Z &&, false, true>();
91+
TrivialityTester<A &&, false, true>();
92+
TrivialityTester<B &&, false, true>();
93+
}
94+
95+
} // namespace triviality
96+
97+
} // end anonymous namespace

llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ unittest("SupportTests") {
8585
"TrailingObjectsTest.cpp",
8686
"TrigramIndexTest.cpp",
8787
"TypeNameTest.cpp",
88+
"TypeTraitsTest.cpp",
8889
"UnicodeTest.cpp",
8990
"VersionTupleTest.cpp",
9091
"VirtualFileSystemTest.cpp",

0 commit comments

Comments
 (0)