Skip to content

Commit

Permalink
Revert "[llvm][NFC] Use c++17 style variable type traits"
Browse files Browse the repository at this point in the history
This reverts commit 1834a31.
  • Loading branch information
njames93 committed Nov 8, 2022
1 parent 46d53f4 commit 632a389
Show file tree
Hide file tree
Showing 43 changed files with 219 additions and 185 deletions.
5 changes: 3 additions & 2 deletions llvm/include/llvm/Support/YAMLTraits.h
Expand Up @@ -2019,8 +2019,9 @@ template <typename T> struct StdMapStringCustomMappingTraitsImpl {
namespace llvm { \
namespace yaml { \
static_assert( \
!std::is_fundamental_v<TYPE> && !std::is_same_v<TYPE, std::string> && \
!std::is_same_v<TYPE, llvm::StringRef>, \
!std::is_fundamental<TYPE>::value && \
!std::is_same<TYPE, std::string>::value && \
!std::is_same<TYPE, llvm::StringRef>::value, \
"only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"); \
template <> struct SequenceElementTraits<TYPE> { \
static const bool flow = FLOW; \
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp
Expand Up @@ -237,7 +237,8 @@ struct LocIndex {
}

template<typename IntT> static LocIndex fromRawInteger(IntT ID) {
static_assert(std::is_unsigned_v<IntT> && sizeof(ID) == sizeof(uint64_t),
static_assert(std::is_unsigned<IntT>::value &&
sizeof(ID) == sizeof(uint64_t),
"Cannot convert raw integer to LocIndex");
return {static_cast<u32_location_t>(ID >> 32),
static_cast<u32_index_t>(ID)};
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/CodeView/EnumTables.cpp
Expand Up @@ -14,7 +14,7 @@ using namespace llvm;
using namespace codeview;

#define CV_ENUM_CLASS_ENT(enum_class, enum) \
{ #enum, std::underlying_type_t<enum_class>(enum_class::enum) }
{ #enum, std::underlying_type < enum_class > ::type(enum_class::enum) }

#define CV_ENUM_ENT(ns, enum) \
{ #enum, ns::enum }
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp
Expand Up @@ -27,7 +27,7 @@ static const EnumEntry<TypeLeafKind> LeafTypeNames[] = {
};

#define ENUM_ENTRY(enum_class, enum) \
{ #enum, std::underlying_type_t<enum_class>(enum_class::enum) }
{ #enum, std::underlying_type < enum_class > ::type(enum_class::enum) }

static const EnumEntry<uint16_t> ClassOptionNames[] = {
ENUM_ENTRY(ClassOptions, Packed),
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/PDB/Native/EnumTables.cpp
Expand Up @@ -14,7 +14,7 @@ using namespace llvm;
using namespace llvm::pdb;

#define PDB_ENUM_CLASS_ENT(enum_class, enum) \
{ #enum, std::underlying_type_t<enum_class>(enum_class::enum) }
{ #enum, std::underlying_type < enum_class > ::type(enum_class::enum) }

#define PDB_ENUM_ENT(ns, enum) \
{ #enum, ns::enum }
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Object/DXContainer.cpp
Expand Up @@ -32,7 +32,7 @@ static Error readStruct(StringRef Buffer, const char *Src, T &Struct) {

template <typename T>
static Error readInteger(StringRef Buffer, const char *Src, T &Val) {
static_assert(std::is_integral_v<T>,
static_assert(std::is_integral<T>::value,
"Cannot call readInteger on non-integral type.");
// Don't read before the beginning or past the end of the file
if (Src < Buffer.begin() || Src + sizeof(T) > Buffer.end())
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ProfileData/InstrProf.cpp
Expand Up @@ -1351,7 +1351,7 @@ uint64_t Header::formatVersion() const {

Expected<Header> Header::readFromBuffer(const unsigned char *Buffer) {
using namespace support;
static_assert(std::is_standard_layout_v<Header>,
static_assert(std::is_standard_layout<Header>::value,
"The header should be standard layout type since we use offset "
"of fields to read.");
Header H;
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Support/ItaniumManglingCanonicalizer.cpp
Expand Up @@ -27,7 +27,8 @@ struct FoldingSetNodeIDBuilder {
ID.AddString(llvm::StringRef(Str.begin(), Str.size()));
}
template <typename T>
std::enable_if_t<std::is_integral_v<T> || std::is_enum_v<T>> operator()(T V) {
std::enable_if_t<std::is_integral<T>::value || std::is_enum<T>::value>
operator()(T V) {
ID.AddInteger((unsigned long long)V);
}
void operator()(itanium_demangle::NodeArray A) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Support/NativeFormatting.cpp
Expand Up @@ -55,7 +55,7 @@ static void writeWithCommas(raw_ostream &S, ArrayRef<char> Buffer) {
template <typename T>
static void write_unsigned_impl(raw_ostream &S, T N, size_t MinDigits,
IntegerStyle Style, bool IsNegative) {
static_assert(std::is_unsigned_v<T>, "Value is not unsigned!");
static_assert(std::is_unsigned<T>::value, "Value is not unsigned!");

char NumberBuffer[128];
std::memset(NumberBuffer, '0', sizeof(NumberBuffer));
Expand Down Expand Up @@ -92,7 +92,7 @@ static void write_unsigned(raw_ostream &S, T N, size_t MinDigits,
template <typename T>
static void write_signed(raw_ostream &S, T N, size_t MinDigits,
IntegerStyle Style) {
static_assert(std::is_signed_v<T>, "Value is not signed!");
static_assert(std::is_signed<T>::value, "Value is not signed!");

using UnsignedT = std::make_unsigned_t<T>;

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Expand Up @@ -3574,8 +3574,8 @@ template <typename T>
static bool hasCalleePopSRet(const SmallVectorImpl<T> &Args,
const X86Subtarget &Subtarget) {
// Not C++20 (yet), so no concepts available.
static_assert(std::is_same_v<T, ISD::OutputArg> ||
std::is_same_v<T, ISD::InputArg>,
static_assert(std::is_same<T, ISD::OutputArg>::value ||
std::is_same<T, ISD::InputArg>::value,
"requires ISD::OutputArg or ISD::InputArg");

// Only 32-bit pops the sret. It's a 64-bit world these days, so early-out
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Scalar/NaryReassociate.cpp
Expand Up @@ -576,13 +576,13 @@ NaryReassociatePass::findClosestMatchingDominator(const SCEV *CandidateExpr,
}

template <typename MaxMinT> static SCEVTypes convertToSCEVype(MaxMinT &MM) {
if (std::is_same_v<smax_pred_ty, typename MaxMinT::PredType>)
if (std::is_same<smax_pred_ty, typename MaxMinT::PredType>::value)
return scSMaxExpr;
else if (std::is_same_v<umax_pred_ty, typename MaxMinT::PredType>)
else if (std::is_same<umax_pred_ty, typename MaxMinT::PredType>::value)
return scUMaxExpr;
else if (std::is_same_v<smin_pred_ty, typename MaxMinT::PredType>)
else if (std::is_same<smin_pred_ty, typename MaxMinT::PredType>::value)
return scSMinExpr;
else if (std::is_same_v<umin_pred_ty, typename MaxMinT::PredType>)
else if (std::is_same<umin_pred_ty, typename MaxMinT::PredType>::value)
return scUMinExpr;

llvm_unreachable("Can't convert MinMax pattern to SCEV type");
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Expand Up @@ -7219,11 +7219,12 @@ namespace {
/// value, otherwise.
struct ValueSelect {
template <typename U>
static std::enable_if_t<std::is_same_v<Value *, U>, Value *> get(Value *V) {
static std::enable_if_t<std::is_same<Value *, U>::value, Value *>
get(Value *V) {
return V;
}
template <typename U>
static std::enable_if_t<!std::is_same_v<Value *, U>, U> get(Value *) {
static std::enable_if_t<!std::is_same<Value *, U>::value, U> get(Value *) {
return U();
}
};
Expand Down
8 changes: 4 additions & 4 deletions llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
Expand Up @@ -256,17 +256,17 @@ class NewArchiveMemberList {
"This test makes sure NewArchiveMemberList is used by MembersData since "
"the following asserts test invariants required for MembersData.");
static_assert(
!std::is_copy_constructible_v<
decltype(NewArchiveMemberList::Members)::value_type>,
!std::is_copy_constructible<
decltype(NewArchiveMemberList::Members)::value_type>::value,
"MembersData::MembersPerArchitecture has a dependency on "
"MembersData::FileBuffers so it should not be able to "
"be copied on its own without FileBuffers. Unfortunately, "
"is_copy_constructible does not detect whether the container (ie vector) "
"of a non-copyable type is itself non-copyable so we have to test the "
"actual type of the stored data (ie, value_type).");
static_assert(
!std::is_copy_assignable_v<
decltype(NewArchiveMemberList::Members)::value_type>,
!std::is_copy_assignable<
decltype(NewArchiveMemberList::Members)::value_type>::value,
"MembersData::MembersPerArchitecture has a dependency on "
"MembersData::FileBuffers so it should not be able to "
"be copied on its own without FileBuffers. Unfortunately, "
Expand Down
41 changes: 24 additions & 17 deletions llvm/unittests/ADT/ArrayRefTest.cpp
Expand Up @@ -16,27 +16,34 @@ using namespace llvm;

// Check that the ArrayRef-of-pointer converting constructor only allows adding
// cv qualifiers (not removing them, or otherwise changing the type)
static_assert(std::is_convertible_v<ArrayRef<int *>, ArrayRef<const int *>>,
"Adding const");
static_assert(std::is_convertible_v<ArrayRef<int *>, ArrayRef<volatile int *>>,
"Adding volatile");
static_assert(!std::is_convertible_v<ArrayRef<int *>, ArrayRef<float *>>,
static_assert(
std::is_convertible<ArrayRef<int *>, ArrayRef<const int *>>::value,
"Adding const");
static_assert(
std::is_convertible<ArrayRef<int *>, ArrayRef<volatile int *>>::value,
"Adding volatile");
static_assert(!std::is_convertible<ArrayRef<int *>, ArrayRef<float *>>::value,
"Changing pointer of one type to a pointer of another");
static_assert(!std::is_convertible_v<ArrayRef<const int *>, ArrayRef<int *>>,
"Removing const");
static_assert(!std::is_convertible_v<ArrayRef<volatile int *>, ArrayRef<int *>>,
"Removing volatile");
static_assert(
!std::is_convertible<ArrayRef<const int *>, ArrayRef<int *>>::value,
"Removing const");
static_assert(
!std::is_convertible<ArrayRef<volatile int *>, ArrayRef<int *>>::value,
"Removing volatile");

// Check that we can't accidentally assign a temporary location to an ArrayRef.
// (Unfortunately we can't make use of the same thing with constructors.)
static_assert(!std::is_assignable_v<ArrayRef<int *> &, int *>,
"Assigning from single prvalue element");
static_assert(!std::is_assignable_v<ArrayRef<int *> &, int *&&>,
"Assigning from single xvalue element");
static_assert(std::is_assignable_v<ArrayRef<int *> &, int *&>,
"Assigning from single lvalue element");
static_assert(
!std::is_assignable_v<ArrayRef<int *> &, std::initializer_list<int *>>,
!std::is_assignable<ArrayRef<int *>&, int *>::value,
"Assigning from single prvalue element");
static_assert(
!std::is_assignable<ArrayRef<int *>&, int * &&>::value,
"Assigning from single xvalue element");
static_assert(
std::is_assignable<ArrayRef<int *>&, int * &>::value,
"Assigning from single lvalue element");
static_assert(
!std::is_assignable<ArrayRef<int *>&, std::initializer_list<int *>>::value,
"Assigning from an initializer list");

namespace {
Expand Down Expand Up @@ -254,7 +261,7 @@ TEST(ArrayRefTest, makeArrayRefFromStdArray) {
}
}

static_assert(std::is_trivially_copyable_v<ArrayRef<int>>,
static_assert(std::is_trivially_copyable<ArrayRef<int>>::value,
"trivially copyable");

TEST(ArrayRefTest, makeMutableArrayRef) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/ADT/DenseMapTest.cpp
Expand Up @@ -682,7 +682,7 @@ struct B : public A {

namespace llvm {
template <typename T>
struct DenseMapInfo<T, std::enable_if_t<std::is_base_of_v<A, T>>> {
struct DenseMapInfo<T, std::enable_if_t<std::is_base_of<A, T>::value>> {
static inline T getEmptyKey() { return {static_cast<int>(~0)}; }
static inline T getTombstoneKey() { return {static_cast<int>(~0U - 1)}; }
static unsigned getHashValue(const T &Val) { return Val.value; }
Expand Down
14 changes: 6 additions & 8 deletions llvm/unittests/ADT/DenseSetTest.cpp
Expand Up @@ -14,14 +14,12 @@ using namespace llvm;

namespace {

static_assert(
std::is_const_v<
std::remove_pointer_t<DenseSet<int>::const_iterator::pointer>>,
"Iterator pointer type should be const");
static_assert(
std::is_const_v<
std::remove_reference_t<DenseSet<int>::const_iterator::reference>>,
"Iterator reference type should be const");
static_assert(std::is_const<std::remove_pointer<
DenseSet<int>::const_iterator::pointer>::type>::value,
"Iterator pointer type should be const");
static_assert(std::is_const<std::remove_reference<
DenseSet<int>::const_iterator::reference>::type>::value,
"Iterator reference type should be const");

// Test hashing with a set of only two entries.
TEST(DenseSetTest, DoubleEntrySetTest) {
Expand Down
10 changes: 5 additions & 5 deletions llvm/unittests/ADT/EnumeratedArrayTest.cpp
Expand Up @@ -106,15 +106,15 @@ enum class Colors { Red, Blue, Green, Last = Green };

using Array = EnumeratedArray<float, Colors, Colors::Last, size_t>;

static_assert(std::is_same_v<Array::value_type, float>,
static_assert(std::is_same<Array::value_type, float>::value,
"Incorrect value_type type");
static_assert(std::is_same_v<Array::reference, float &>,
static_assert(std::is_same<Array::reference, float &>::value,
"Incorrect reference type!");
static_assert(std::is_same_v<Array::pointer, float *>,
static_assert(std::is_same<Array::pointer, float *>::value,
"Incorrect pointer type!");
static_assert(std::is_same_v<Array::const_reference, const float &>,
static_assert(std::is_same<Array::const_reference, const float &>::value,
"Incorrect const_reference type!");
static_assert(std::is_same_v<Array::const_pointer, const float *>,
static_assert(std::is_same<Array::const_pointer, const float *>::value,
"Incorrect const_pointer type!");
} // namespace

Expand Down
14 changes: 8 additions & 6 deletions llvm/unittests/ADT/IListIteratorTest.cpp
Expand Up @@ -158,14 +158,16 @@ TEST(IListIteratorTest, ReverseConstructor) {
EXPECT_EQ(CL.rbegin(), const_reverse_iterator(CL.end()));

// Confirm lack of implicit conversions.
static_assert(!std::is_convertible_v<iterator, reverse_iterator>,
static_assert(!std::is_convertible<iterator, reverse_iterator>::value,
"unexpected implicit conversion");
static_assert(!std::is_convertible_v<reverse_iterator, iterator>,
"unexpected implicit conversion");
static_assert(!std::is_convertible_v<const_iterator, const_reverse_iterator>,
"unexpected implicit conversion");
static_assert(!std::is_convertible_v<const_reverse_iterator, const_iterator>,
static_assert(!std::is_convertible<reverse_iterator, iterator>::value,
"unexpected implicit conversion");
static_assert(
!std::is_convertible<const_iterator, const_reverse_iterator>::value,
"unexpected implicit conversion");
static_assert(
!std::is_convertible<const_reverse_iterator, const_iterator>::value,
"unexpected implicit conversion");
}

} // end namespace
37 changes: 19 additions & 18 deletions llvm/unittests/ADT/IListNodeTest.cpp
Expand Up @@ -22,46 +22,47 @@ struct TagB {};

TEST(IListNodeTest, Options) {
static_assert(
std::is_same_v<compute_node_options<Node>::type,
compute_node_options<Node, ilist_tag<void>>::type>,
std::is_same<compute_node_options<Node>::type,
compute_node_options<Node, ilist_tag<void>>::type>::value,
"default tag is void");
static_assert(
!std::is_same_v<compute_node_options<Node, ilist_tag<TagA>>::type,
compute_node_options<Node, ilist_tag<void>>::type>,
!std::is_same<compute_node_options<Node, ilist_tag<TagA>>::type,
compute_node_options<Node, ilist_tag<void>>::type>::value,
"default tag is void, different from TagA");
static_assert(
!std::is_same_v<compute_node_options<Node, ilist_tag<TagA>>::type,
compute_node_options<Node, ilist_tag<TagB>>::type>,
!std::is_same<compute_node_options<Node, ilist_tag<TagA>>::type,
compute_node_options<Node, ilist_tag<TagB>>::type>::value,
"TagA is not TagB");
static_assert(
std::is_same_v<
std::is_same<
compute_node_options<Node, ilist_sentinel_tracking<false>>::type,
compute_node_options<Node, ilist_sentinel_tracking<false>,
ilist_tag<void>>::type>,
ilist_tag<void>>::type>::value,
"default tag is void, even with sentinel tracking off");
static_assert(
std::is_same_v<
std::is_same<
compute_node_options<Node, ilist_sentinel_tracking<false>>::type,
compute_node_options<Node, ilist_tag<void>,
ilist_sentinel_tracking<false>>::type>,
ilist_sentinel_tracking<false>>::type>::value,
"order shouldn't matter");
static_assert(
std::is_same_v<
std::is_same<
compute_node_options<Node, ilist_sentinel_tracking<true>>::type,
compute_node_options<Node, ilist_sentinel_tracking<true>,
ilist_tag<void>>::type>,
ilist_tag<void>>::type>::value,
"default tag is void, even with sentinel tracking on");
static_assert(
std::is_same_v<
std::is_same<
compute_node_options<Node, ilist_sentinel_tracking<true>>::type,
compute_node_options<Node, ilist_tag<void>,
ilist_sentinel_tracking<true>>::type>,
ilist_sentinel_tracking<true>>::type>::value,
"order shouldn't matter");
static_assert(
std::is_same_v<compute_node_options<Node, ilist_sentinel_tracking<true>,
ilist_tag<TagA>>::type,
compute_node_options<Node, ilist_tag<TagA>,
ilist_sentinel_tracking<true>>::type>,
std::is_same<
compute_node_options<Node, ilist_sentinel_tracking<true>,
ilist_tag<TagA>>::type,
compute_node_options<Node, ilist_tag<TagA>,
ilist_sentinel_tracking<true>>::type>::value,
"order shouldn't matter with real tags");
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/ADT/ImmutableListTest.cpp
Expand Up @@ -266,7 +266,7 @@ TEST_F(ImmutableListTest, LongListOrderingTest) {
ASSERT_EQ(6, i);
}

static_assert(std::is_trivially_copyable_v<ImmutableList<Wrapper<long>>>,
static_assert(std::is_trivially_copyable<ImmutableList<Wrapper<long>>>::value,
"trivially copyable");

} // namespace

0 comments on commit 632a389

Please sign in to comment.