Skip to content

Commit

Permalink
Revert "Switch to std::is_trivially_move_constructible and std::is_tr…
Browse files Browse the repository at this point in the history
…ivially_copy_constructible"

This reverts commit c8d406c.

Builds are broken with some versions of GCC.
  • Loading branch information
joker-eph committed Dec 3, 2020
1 parent f6b9afa commit 6cd9608
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 5 deletions.
6 changes: 3 additions & 3 deletions llvm/include/llvm/ADT/FunctionExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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 ReturnT, typename... ParamTs> class UniqueFunctionBase {
Expand All @@ -83,8 +83,8 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
template <typename T>
using AdjustedParamT = typename std::conditional<
!std::is_reference<T>::value &&
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;

Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/ADT/SmallVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (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> {
protected:
Expand Down
37 changes: 37 additions & 0 deletions llvm/include/llvm/Support/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ 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 {
Expand All @@ -78,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>
Expand Down
1 change: 1 addition & 0 deletions llvm/unittests/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ add_llvm_unittest(SupportTests
TimerTest.cpp
ToolOutputFileTest.cpp
TypeNameTest.cpp
TypeTraitsTest.cpp
TrailingObjectsTest.cpp
TrigramIndexTest.cpp
UnicodeTest.cpp
Expand Down
97 changes: 97 additions & 0 deletions llvm/unittests/Support/TypeTraitsTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//===- 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
1 change: 1 addition & 0 deletions llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ unittest("SupportTests") {
"TrailingObjectsTest.cpp",
"TrigramIndexTest.cpp",
"TypeNameTest.cpp",
"TypeTraitsTest.cpp",
"UnicodeTest.cpp",
"VersionTupleTest.cpp",
"VirtualFileSystemTest.cpp",
Expand Down

0 comments on commit 6cd9608

Please sign in to comment.