From 649f05aa245ba4207667f9564b27d44b44f6d3ae Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 2 Dec 2020 22:02:48 -0800 Subject: [PATCH] Switch from llvm::is_trivially_copyable to std::is_trivially_copyable GCC<5 did not support std::is_trivially_copyable. Now LLVM builds require 5.1 we can migrate to std::is_trivially_copyable. The Optional.h change made MSVC choke (https://buildkite.com/llvm-project/premerge-checks/builds/18587#cd1bb616-ffdc-4581-9795-b42c284196de) so I leave it out for now. Differential Revision: https://reviews.llvm.org/D92514 --- docs/ProgrammersManual.rst | 2 +- include/llvm/ADT/DenseMap.h | 4 ++-- include/llvm/ADT/STLExtras.h | 2 +- include/llvm/DebugInfo/CodeView/TypeHashing.h | 5 ----- tools/llvm-diff/DifferenceEngine.cpp | 2 +- unittests/ADT/ArrayRefTest.cpp | 2 +- unittests/ADT/ImmutableListTest.cpp | 2 +- unittests/ADT/OptionalTest.cpp | 19 +++++++++---------- unittests/ADT/PointerIntPairTest.cpp | 4 ++-- unittests/ADT/StringRefTest.cpp | 3 ++- unittests/Analysis/BlockFrequencyInfoTest.cpp | 2 +- unittests/Bitstream/BitstreamReaderTest.cpp | 2 +- unittests/CodeGen/MachineInstrTest.cpp | 3 ++- unittests/CodeGen/TypeTraitsTest.cpp | 14 +++++++++----- unittests/IR/CFGBuilder.cpp | 9 +++++---- unittests/Support/ScaledNumberTest.cpp | 2 +- 16 files changed, 39 insertions(+), 38 deletions(-) diff --git a/docs/ProgrammersManual.rst b/docs/ProgrammersManual.rst index d9925d69d9f..e303a7a18eb 100644 --- a/docs/ProgrammersManual.rst +++ b/docs/ProgrammersManual.rst @@ -1530,7 +1530,7 @@ SmallVector has grown a few other minor advantages over std::vector, causing #. std::vector is exception-safe, and some implementations have pessimizations that copy elements when SmallVector would move them. -#. SmallVector understands ``llvm::is_trivially_copyable`` and uses realloc aggressively. +#. SmallVector understands ``std::is_trivially_copyable`` and uses realloc aggressively. #. Many LLVM APIs take a SmallVectorImpl as an out parameter (see the note below). diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h index 42e4fc84175..7f7a4593ae3 100644 --- a/include/llvm/ADT/DenseMap.h +++ b/include/llvm/ADT/DenseMap.h @@ -426,8 +426,8 @@ protected: setNumEntries(other.getNumEntries()); setNumTombstones(other.getNumTombstones()); - if (is_trivially_copyable::value && - is_trivially_copyable::value) + if (std::is_trivially_copyable::value && + std::is_trivially_copyable::value) memcpy(reinterpret_cast(getBuckets()), other.getBuckets(), getNumBuckets() * sizeof(BucketT)); else diff --git a/include/llvm/ADT/STLExtras.h b/include/llvm/ADT/STLExtras.h index 5a5d47b783c..1d6faf6509f 100644 --- a/include/llvm/ADT/STLExtras.h +++ b/include/llvm/ADT/STLExtras.h @@ -1428,7 +1428,7 @@ template // is trivially copyable. using sort_trivially_copyable = conjunction< std::is_pointer, - is_trivially_copyable::value_type>>; + std::is_trivially_copyable::value_type>>; } // namespace detail // Provide wrappers to std::sort which shuffle the elements before sorting diff --git a/include/llvm/DebugInfo/CodeView/TypeHashing.h b/include/llvm/DebugInfo/CodeView/TypeHashing.h index e6ade770457..9f34d026b1b 100644 --- a/include/llvm/DebugInfo/CodeView/TypeHashing.h +++ b/include/llvm/DebugInfo/CodeView/TypeHashing.h @@ -171,15 +171,10 @@ struct GloballyHashedType { return Hashes; } }; -#if defined(_MSC_VER) -// is_trivially_copyable is not available in older versions of libc++, but it is -// available in all supported versions of MSVC, so at least this gives us some -// coverage. static_assert(std::is_trivially_copyable::value, "GloballyHashedType must be trivially copyable so that we can " "reinterpret_cast arrays of hash data to arrays of " "GloballyHashedType"); -#endif } // namespace codeview template <> struct DenseMapInfo { diff --git a/tools/llvm-diff/DifferenceEngine.cpp b/tools/llvm-diff/DifferenceEngine.cpp index 2cf1afbc6af..64c0dc61e80 100644 --- a/tools/llvm-diff/DifferenceEngine.cpp +++ b/tools/llvm-diff/DifferenceEngine.cpp @@ -67,7 +67,7 @@ public: unsigned NewSize = Storage.size() - 1; if (NewSize) { // Move the slot at the end to the beginning. - if (is_trivially_copyable::value) + if (std::is_trivially_copyable::value) Storage[0] = Storage[NewSize]; else std::swap(Storage[0], Storage[NewSize]); diff --git a/unittests/ADT/ArrayRefTest.cpp b/unittests/ADT/ArrayRefTest.cpp index 4690319ae52..f3da4c675a8 100644 --- a/unittests/ADT/ArrayRefTest.cpp +++ b/unittests/ADT/ArrayRefTest.cpp @@ -262,7 +262,7 @@ TEST(ArrayRefTest, makeArrayRefFromStdArray) { } } -static_assert(is_trivially_copyable>::value, +static_assert(std::is_trivially_copyable>::value, "trivially copyable"); } // end anonymous namespace diff --git a/unittests/ADT/ImmutableListTest.cpp b/unittests/ADT/ImmutableListTest.cpp index b0b1e0e6c29..ab3b8b472b9 100644 --- a/unittests/ADT/ImmutableListTest.cpp +++ b/unittests/ADT/ImmutableListTest.cpp @@ -267,7 +267,7 @@ TEST_F(ImmutableListTest, LongListOrderingTest) { ASSERT_EQ(6, i); } -static_assert(is_trivially_copyable>>::value, +static_assert(std::is_trivially_copyable>>::value, "trivially copyable"); } // namespace diff --git a/unittests/ADT/OptionalTest.cpp b/unittests/ADT/OptionalTest.cpp index 249c9268bcf..7506453c4d9 100644 --- a/unittests/ADT/OptionalTest.cpp +++ b/unittests/ADT/OptionalTest.cpp @@ -17,10 +17,10 @@ using namespace llvm; -static_assert(is_trivially_copyable>::value, - "trivially copyable"); +static_assert(std::is_trivially_copyable>::value, + "trivially copyable"); -static_assert(is_trivially_copyable>>::value, +static_assert(std::is_trivially_copyable>>::value, "trivially copyable"); void OptionalWorksInConstexpr() { @@ -66,8 +66,8 @@ unsigned NonDefaultConstructible::Destructions = 0; unsigned NonDefaultConstructible::CopyAssignments = 0; static_assert( - !is_trivially_copyable>::value, - "not trivially copyable"); + !std::is_trivially_copyable>::value, + "not trivially copyable"); // Test fixture class OptionalTest : public testing::Test { @@ -227,9 +227,8 @@ struct MultiArgConstructor { }; unsigned MultiArgConstructor::Destructions = 0; -static_assert( - !is_trivially_copyable>::value, - "not trivially copyable"); +static_assert(!std::is_trivially_copyable>::value, + "not trivially copyable"); TEST_F(OptionalTest, Emplace) { MultiArgConstructor::ResetCounts(); @@ -278,7 +277,7 @@ unsigned MoveOnly::MoveConstructions = 0; unsigned MoveOnly::Destructions = 0; unsigned MoveOnly::MoveAssignments = 0; -static_assert(!is_trivially_copyable>::value, +static_assert(!std::is_trivially_copyable>::value, "not trivially copyable"); TEST_F(OptionalTest, MoveOnlyNull) { @@ -382,7 +381,7 @@ private: unsigned Immovable::Constructions = 0; unsigned Immovable::Destructions = 0; -static_assert(!is_trivially_copyable>::value, +static_assert(!std::is_trivially_copyable>::value, "not trivially copyable"); TEST_F(OptionalTest, ImmovableEmplace) { diff --git a/unittests/ADT/PointerIntPairTest.cpp b/unittests/ADT/PointerIntPairTest.cpp index b8ba3e32b28..8a42e5b9f55 100644 --- a/unittests/ADT/PointerIntPairTest.cpp +++ b/unittests/ADT/PointerIntPairTest.cpp @@ -62,7 +62,7 @@ TEST(PointerIntPairTest, GetSet) { EXPECT_EQ(&s, Pair2.getPointer()); EXPECT_EQ(E::Case3, Pair2.getInt()); - static_assert(is_trivially_copyable>::value, + static_assert(std::is_trivially_copyable>::value, "trivially copyable"); } @@ -101,7 +101,7 @@ TEST(PointerIntPairTest, ManyUnusedBits) { (int)PointerLikeTypeTraits::NumLowBitsAvailable); static_assert( - is_trivially_copyable< + std::is_trivially_copyable< PointerIntPair>::value, "trivially copyable"); } diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index fbf2d8422a4..50e38c50f62 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -1087,6 +1087,7 @@ TEST(StringRefTest, GTestPrinter) { EXPECT_EQ(R"("foo")", ::testing::PrintToString(StringRef("foo"))); } -static_assert(is_trivially_copyable::value, "trivially copyable"); +static_assert(std::is_trivially_copyable::value, + "trivially copyable"); } // end anonymous namespace diff --git a/unittests/Analysis/BlockFrequencyInfoTest.cpp b/unittests/Analysis/BlockFrequencyInfoTest.cpp index 2aeba947a74..5dd39951716 100644 --- a/unittests/Analysis/BlockFrequencyInfoTest.cpp +++ b/unittests/Analysis/BlockFrequencyInfoTest.cpp @@ -91,7 +91,7 @@ TEST_F(BlockFrequencyInfoTest, Basic) { EXPECT_EQ(BFI.getBlockFreq(BB3).getFrequency(), BB3Freq); } -static_assert(is_trivially_copyable::value, +static_assert(std::is_trivially_copyable::value, "trivially copyable"); } // end anonymous namespace diff --git a/unittests/Bitstream/BitstreamReaderTest.cpp b/unittests/Bitstream/BitstreamReaderTest.cpp index f58af220f2d..669288e4264 100644 --- a/unittests/Bitstream/BitstreamReaderTest.cpp +++ b/unittests/Bitstream/BitstreamReaderTest.cpp @@ -161,7 +161,7 @@ TEST(BitstreamReaderTest, shortRead) { } } -static_assert(is_trivially_copyable::value, +static_assert(std::is_trivially_copyable::value, "trivially copyable"); } // end anonymous namespace diff --git a/unittests/CodeGen/MachineInstrTest.cpp b/unittests/CodeGen/MachineInstrTest.cpp index 33baaf62efd..7c9faeca829 100644 --- a/unittests/CodeGen/MachineInstrTest.cpp +++ b/unittests/CodeGen/MachineInstrTest.cpp @@ -383,6 +383,7 @@ TEST(MachineInstrExtraInfo, RemoveExtraInfo) { ASSERT_FALSE(MI->getHeapAllocMarker()); } -static_assert(is_trivially_copyable::value, "trivially copyable"); +static_assert(std::is_trivially_copyable::value, + "trivially copyable"); } // end namespace diff --git a/unittests/CodeGen/TypeTraitsTest.cpp b/unittests/CodeGen/TypeTraitsTest.cpp index 840375bd4ab..af1f36c1e94 100644 --- a/unittests/CodeGen/TypeTraitsTest.cpp +++ b/unittests/CodeGen/TypeTraitsTest.cpp @@ -12,14 +12,18 @@ #include "llvm/CodeGen/SlotIndexes.h" #include "llvm/CodeGen/TargetPassConfig.h" #include "gtest/gtest.h" +#include using namespace llvm; #if __has_feature(is_trivially_copyable) || (defined(__GNUC__) && __GNUC__ >= 5) -static_assert(is_trivially_copyable::value, "trivially copyable"); -static_assert(is_trivially_copyable::value, "trivially copyable"); -static_assert(is_trivially_copyable::value, "trivially copyable"); -static_assert(is_trivially_copyable::value, "trivially copyable"); -static_assert(is_trivially_copyable::value, "trivially copyable"); +static_assert(std::is_trivially_copyable::value, + "trivially copyable"); +static_assert(std::is_trivially_copyable::value, "trivially copyable"); +static_assert(std::is_trivially_copyable::value, "trivially copyable"); +static_assert(std::is_trivially_copyable::value, + "trivially copyable"); +static_assert(std::is_trivially_copyable::value, + "trivially copyable"); #endif diff --git a/unittests/IR/CFGBuilder.cpp b/unittests/IR/CFGBuilder.cpp index 3583ab2a8a5..c9bc52ca7a6 100644 --- a/unittests/IR/CFGBuilder.cpp +++ b/unittests/IR/CFGBuilder.cpp @@ -267,10 +267,11 @@ TEST(CFGBuilder, Rebuild) { EXPECT_TRUE(isa(B.getOrAddBlock("d")->getTerminator())); } -static_assert(is_trivially_copyable::value, +static_assert(std::is_trivially_copyable::value, "trivially copyable"); -static_assert(is_trivially_copyable::value, +static_assert(std::is_trivially_copyable::value, "trivially copyable"); -static_assert(is_trivially_copyable::value, "trivially copyable"); -static_assert(is_trivially_copyable::value, +static_assert(std::is_trivially_copyable::value, + "trivially copyable"); +static_assert(std::is_trivially_copyable::value, "trivially copyable"); diff --git a/unittests/Support/ScaledNumberTest.cpp b/unittests/Support/ScaledNumberTest.cpp index 3fa63b7bf3c..82ecce09444 100644 --- a/unittests/Support/ScaledNumberTest.cpp +++ b/unittests/Support/ScaledNumberTest.cpp @@ -562,7 +562,7 @@ TEST(ScaledNumberHelpersTest, toIntBug) { EXPECT_EQ(1u, (n * n).toInt()); } -static_assert(is_trivially_copyable>::value, +static_assert(std::is_trivially_copyable>::value, "trivially copyable"); } // end namespace