diff options
Diffstat (limited to 'llvm/unittests')
57 files changed, 664 insertions, 200 deletions
diff --git a/llvm/unittests/ADT/APFloatTest.cpp b/llvm/unittests/ADT/APFloatTest.cpp index fbe96bb..99cc38b 100644 --- a/llvm/unittests/ADT/APFloatTest.cpp +++ b/llvm/unittests/ADT/APFloatTest.cpp @@ -10118,7 +10118,7 @@ TEST(APFloatTest, Float4E2M1FNToFloat) { } TEST(APFloatTest, AddOrSubtractSignificand) { - typedef detail::IEEEFloatUnitTestHelper Helper; + using Helper = detail::IEEEFloatUnitTestHelper; // Test cases are all combinations of: // {equal exponents, LHS larger exponent, RHS larger exponent} // {equal significands, LHS larger significand, RHS larger significand} diff --git a/llvm/unittests/ADT/BitVectorTest.cpp b/llvm/unittests/ADT/BitVectorTest.cpp index 12ba004..e13523b 100644 --- a/llvm/unittests/ADT/BitVectorTest.cpp +++ b/llvm/unittests/ADT/BitVectorTest.cpp @@ -21,7 +21,7 @@ template <typename T> class BitVectorTest : public ::testing::Test { }; // Test both BitVector and SmallBitVector with the same suite of tests. -typedef ::testing::Types<BitVector, SmallBitVector> BitVectorTestTypes; +using BitVectorTestTypes = ::testing::Types<BitVector, SmallBitVector>; TYPED_TEST_SUITE(BitVectorTest, BitVectorTestTypes, ); TYPED_TEST(BitVectorTest, TrivialOperation) { @@ -857,7 +857,7 @@ TYPED_TEST(BitVectorTest, BinOps) { EXPECT_FALSE(B.anyCommon(A)); } -typedef std::vector<std::pair<int, int>> RangeList; +using RangeList = std::vector<std::pair<int, int>>; template <typename VecType> static inline VecType createBitVector(uint32_t Size, diff --git a/llvm/unittests/ADT/BreadthFirstIteratorTest.cpp b/llvm/unittests/ADT/BreadthFirstIteratorTest.cpp index a737390..571e4d2 100644 --- a/llvm/unittests/ADT/BreadthFirstIteratorTest.cpp +++ b/llvm/unittests/ADT/BreadthFirstIteratorTest.cpp @@ -21,7 +21,7 @@ using namespace llvm; namespace llvm { TEST(BreadthFristIteratorTest, Basic) { - typedef bf_iterator<Graph<4>> BFIter; + using BFIter = bf_iterator<Graph<4>>; Graph<4> G; G.AddEdge(0, 1); @@ -46,7 +46,7 @@ TEST(BreadthFristIteratorTest, Basic) { } TEST(BreadthFristIteratorTest, Cycle) { - typedef bf_iterator<Graph<4>> BFIter; + using BFIter = bf_iterator<Graph<4>>; Graph<4> G; G.AddEdge(0, 1); diff --git a/llvm/unittests/ADT/DAGDeltaAlgorithmTest.cpp b/llvm/unittests/ADT/DAGDeltaAlgorithmTest.cpp index f5439478..918a2e6 100644 --- a/llvm/unittests/ADT/DAGDeltaAlgorithmTest.cpp +++ b/llvm/unittests/ADT/DAGDeltaAlgorithmTest.cpp @@ -15,7 +15,7 @@ using namespace llvm; namespace { -typedef DAGDeltaAlgorithm::edge_ty edge_ty; +using edge_ty = DAGDeltaAlgorithm::edge_ty; class FixedDAGDeltaAlgorithm : public DAGDeltaAlgorithm { changeset_ty FailingSet; diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp index aceb4f3..273ee09 100644 --- a/llvm/unittests/ADT/DenseMapTest.cpp +++ b/llvm/unittests/ADT/DenseMapTest.cpp @@ -129,18 +129,17 @@ typename T::mapped_type *const DenseMapTest<T>::dummy_value_ptr = nullptr; // Register these types for testing. // clang-format off -typedef ::testing::Types<DenseMap<uint32_t, uint32_t>, - DenseMap<uint32_t *, uint32_t *>, - DenseMap<CtorTester, CtorTester, CtorTesterMapInfo>, - DenseMap<EnumClass, uint32_t>, - DenseMap<std::optional<uint32_t>, uint32_t>, - SmallDenseMap<uint32_t, uint32_t>, - SmallDenseMap<uint32_t *, uint32_t *>, - SmallDenseMap<CtorTester, CtorTester, 4, - CtorTesterMapInfo>, - SmallDenseMap<EnumClass, uint32_t>, - SmallDenseMap<std::optional<uint32_t>, uint32_t> - > DenseMapTestTypes; +using DenseMapTestTypes = ::testing::Types< + DenseMap<uint32_t, uint32_t>, + DenseMap<uint32_t *, uint32_t *>, + DenseMap<CtorTester, CtorTester, CtorTesterMapInfo>, + DenseMap<EnumClass, uint32_t>, + DenseMap<std::optional<uint32_t>, uint32_t>, + SmallDenseMap<uint32_t, uint32_t>, + SmallDenseMap<uint32_t *, uint32_t *>, + SmallDenseMap<CtorTester, CtorTester, 4, CtorTesterMapInfo>, + SmallDenseMap<EnumClass, uint32_t>, + SmallDenseMap<std::optional<uint32_t>, uint32_t>>; // clang-format on TYPED_TEST_SUITE(DenseMapTest, DenseMapTestTypes, ); diff --git a/llvm/unittests/ADT/DenseSetTest.cpp b/llvm/unittests/ADT/DenseSetTest.cpp index a24f99b..a2a062b 100644 --- a/llvm/unittests/ADT/DenseSetTest.cpp +++ b/llvm/unittests/ADT/DenseSetTest.cpp @@ -96,13 +96,13 @@ private: }; // Register these types for testing. -typedef ::testing::Types<DenseSet<unsigned, TestDenseSetInfo>, - const DenseSet<unsigned, TestDenseSetInfo>, - SmallDenseSet<unsigned, 1, TestDenseSetInfo>, - SmallDenseSet<unsigned, 4, TestDenseSetInfo>, - const SmallDenseSet<unsigned, 4, TestDenseSetInfo>, - SmallDenseSet<unsigned, 64, TestDenseSetInfo>> - DenseSetTestTypes; +using DenseSetTestTypes = + ::testing::Types<DenseSet<unsigned, TestDenseSetInfo>, + const DenseSet<unsigned, TestDenseSetInfo>, + SmallDenseSet<unsigned, 1, TestDenseSetInfo>, + SmallDenseSet<unsigned, 4, TestDenseSetInfo>, + const SmallDenseSet<unsigned, 4, TestDenseSetInfo>, + SmallDenseSet<unsigned, 64, TestDenseSetInfo>>; TYPED_TEST_SUITE(DenseSetTest, DenseSetTestTypes, ); TYPED_TEST(DenseSetTest, Constructor) { diff --git a/llvm/unittests/ADT/DepthFirstIteratorTest.cpp b/llvm/unittests/ADT/DepthFirstIteratorTest.cpp index f792878..00312ca 100644 --- a/llvm/unittests/ADT/DepthFirstIteratorTest.cpp +++ b/llvm/unittests/ADT/DepthFirstIteratorTest.cpp @@ -21,7 +21,7 @@ using namespace llvm; namespace llvm { template <typename T> struct CountedSet { - typedef typename SmallPtrSet<T, 4>::iterator iterator; + using iterator = typename SmallPtrSet<T, 4>::iterator; SmallPtrSet<T, 4> S; int InsertVisited = 0; @@ -44,8 +44,8 @@ public: }; TEST(DepthFirstIteratorTest, ActuallyUpdateIterator) { - typedef CountedSet<Graph<3>::NodeType *> StorageT; - typedef df_iterator<Graph<3>, StorageT, true> DFIter; + using StorageT = CountedSet<Graph<3>::NodeType *>; + using DFIter = df_iterator<Graph<3>, StorageT, true>; Graph<3> G; G.AddEdge(0, 1); diff --git a/llvm/unittests/ADT/IListBaseTest.cpp b/llvm/unittests/ADT/IListBaseTest.cpp index bd91568..eeed488 100644 --- a/llvm/unittests/ADT/IListBaseTest.cpp +++ b/llvm/unittests/ADT/IListBaseTest.cpp @@ -19,13 +19,14 @@ template <typename T> class IListBaseTest : public ::testing::Test {}; class Parent; // Test variants with the same test. -typedef ::testing::Types<ilist_base<false, void>, ilist_base<true, void>, ilist_base<false, Parent*>, ilist_base<true, Parent*>> - IListBaseTestTypes; +using IListBaseTestTypes = + ::testing::Types<ilist_base<false, void>, ilist_base<true, void>, + ilist_base<false, Parent *>, ilist_base<true, Parent *>>; TYPED_TEST_SUITE(IListBaseTest, IListBaseTestTypes, ); TYPED_TEST(IListBaseTest, insertBeforeImpl) { - typedef TypeParam list_base_type; - typedef typename list_base_type::node_base_type node_base_type; + using list_base_type = TypeParam; + using node_base_type = typename list_base_type::node_base_type; node_base_type S, A, B; @@ -51,8 +52,8 @@ TYPED_TEST(IListBaseTest, insertBeforeImpl) { } TYPED_TEST(IListBaseTest, removeImpl) { - typedef TypeParam list_base_type; - typedef typename list_base_type::node_base_type node_base_type; + using list_base_type = TypeParam; + using node_base_type = typename list_base_type::node_base_type; node_base_type S, A, B; @@ -80,8 +81,8 @@ TYPED_TEST(IListBaseTest, removeImpl) { } TYPED_TEST(IListBaseTest, removeRangeImpl) { - typedef TypeParam list_base_type; - typedef typename list_base_type::node_base_type node_base_type; + using list_base_type = TypeParam; + using node_base_type = typename list_base_type::node_base_type; node_base_type S, A, B, C, D; @@ -106,8 +107,8 @@ TYPED_TEST(IListBaseTest, removeRangeImpl) { } TYPED_TEST(IListBaseTest, removeRangeImplAllButSentinel) { - typedef TypeParam list_base_type; - typedef typename list_base_type::node_base_type node_base_type; + using list_base_type = TypeParam; + using node_base_type = typename list_base_type::node_base_type; node_base_type S, A, B; @@ -126,8 +127,8 @@ TYPED_TEST(IListBaseTest, removeRangeImplAllButSentinel) { } TYPED_TEST(IListBaseTest, transferBeforeImpl) { - typedef TypeParam list_base_type; - typedef typename list_base_type::node_base_type node_base_type; + using list_base_type = TypeParam; + using node_base_type = typename list_base_type::node_base_type; node_base_type S1, S2, A, B, C, D, E; diff --git a/llvm/unittests/ADT/IListIteratorTest.cpp b/llvm/unittests/ADT/IListIteratorTest.cpp index 4e5b847b..54a42582 100644 --- a/llvm/unittests/ADT/IListIteratorTest.cpp +++ b/llvm/unittests/ADT/IListIteratorTest.cpp @@ -141,10 +141,10 @@ TEST(IListIteratorTest, ReverseConstructor) { L.insert(L.end(), B); // Save typing. - typedef simple_ilist<Node>::iterator iterator; - typedef simple_ilist<Node>::reverse_iterator reverse_iterator; - typedef simple_ilist<Node>::const_iterator const_iterator; - typedef simple_ilist<Node>::const_reverse_iterator const_reverse_iterator; + using iterator = simple_ilist<Node>::iterator; + using reverse_iterator = simple_ilist<Node>::reverse_iterator; + using const_iterator = simple_ilist<Node>::const_iterator; + using const_reverse_iterator = simple_ilist<Node>::const_reverse_iterator; // Check conversion values. EXPECT_EQ(L.begin(), iterator(L.rend())); diff --git a/llvm/unittests/ADT/IListNodeBaseTest.cpp b/llvm/unittests/ADT/IListNodeBaseTest.cpp index ef90c71..393f83a 100644 --- a/llvm/unittests/ADT/IListNodeBaseTest.cpp +++ b/llvm/unittests/ADT/IListNodeBaseTest.cpp @@ -17,10 +17,10 @@ namespace { class Parent {}; -typedef ilist_node_base<false, void> RawNode; -typedef ilist_node_base<true, void> TrackingNode; -typedef ilist_node_base<false, Parent> ParentNode; -typedef ilist_node_base<true, Parent> ParentTrackingNode; +using RawNode = ilist_node_base<false, void>; +using TrackingNode = ilist_node_base<true, void>; +using ParentNode = ilist_node_base<false, Parent>; +using ParentTrackingNode = ilist_node_base<true, Parent>; TEST(IListNodeBaseTest, DefaultConstructor) { RawNode A; diff --git a/llvm/unittests/ADT/IListSentinelTest.cpp b/llvm/unittests/ADT/IListSentinelTest.cpp index 1f4a831..709a1a4 100644 --- a/llvm/unittests/ADT/IListSentinelTest.cpp +++ b/llvm/unittests/ADT/IListSentinelTest.cpp @@ -14,18 +14,17 @@ using namespace llvm; namespace { template <class T, class... Options> struct PickSentinel { - typedef ilist_sentinel< - typename ilist_detail::compute_node_options<T, Options...>::type> - type; + using type = ilist_sentinel< + typename ilist_detail::compute_node_options<T, Options...>::type>; }; class Node : public ilist_node<Node> {}; class TrackingNode : public ilist_node<Node, ilist_sentinel_tracking<true>> {}; -typedef PickSentinel<Node>::type Sentinel; -typedef PickSentinel<Node, ilist_sentinel_tracking<true>>::type - TrackingSentinel; -typedef PickSentinel<Node, ilist_sentinel_tracking<false>>::type - NoTrackingSentinel; +using Sentinel = PickSentinel<Node>::type; +using TrackingSentinel = + PickSentinel<Node, ilist_sentinel_tracking<true>>::type; +using NoTrackingSentinel = + PickSentinel<Node, ilist_sentinel_tracking<false>>::type; struct LocalAccess : ilist_detail::NodeAccess { using NodeAccess::getPrev; diff --git a/llvm/unittests/ADT/IntervalMapTest.cpp b/llvm/unittests/ADT/IntervalMapTest.cpp index 99a93ab..38f397f 100644 --- a/llvm/unittests/ADT/IntervalMapTest.cpp +++ b/llvm/unittests/ADT/IntervalMapTest.cpp @@ -14,9 +14,9 @@ using namespace llvm; namespace { -typedef IntervalMap<unsigned, unsigned, 4> UUMap; -typedef IntervalMap<unsigned, unsigned, 4, - IntervalMapHalfOpenInfo<unsigned>> UUHalfOpenMap; +using UUMap = IntervalMap<unsigned, unsigned, 4>; +using UUHalfOpenMap = + IntervalMap<unsigned, unsigned, 4, IntervalMapHalfOpenInfo<unsigned>>; // Empty map tests TEST(IntervalMapTest, EmptyMap) { @@ -713,7 +713,7 @@ TEST(IntervalMapTest, OverlapsHalfOpen) { } TEST(IntervalMapOverlapsTest, SmallMaps) { - typedef IntervalMapOverlaps<UUMap,UUMap> UUOverlaps; + using UUOverlaps = IntervalMapOverlaps<UUMap, UUMap>; UUMap::Allocator allocator; UUMap mapA(allocator); UUMap mapB(allocator); @@ -757,7 +757,7 @@ TEST(IntervalMapOverlapsTest, SmallMaps) { } TEST(IntervalMapOverlapsTest, BigMaps) { - typedef IntervalMapOverlaps<UUMap,UUMap> UUOverlaps; + using UUOverlaps = IntervalMapOverlaps<UUMap, UUMap>; UUMap::Allocator allocator; UUMap mapA(allocator); UUMap mapB(allocator); diff --git a/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp b/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp index f4f2083..6da4227 100644 --- a/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp +++ b/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp @@ -25,9 +25,9 @@ struct SimpleRefCounted : Base<SimpleRefCounted<Base>> { template <typename T> struct IntrusiveRefCntPtrTest : testing::Test {}; -typedef ::testing::Types<SimpleRefCounted<RefCountedBase>, - SimpleRefCounted<ThreadSafeRefCountedBase>> - IntrusiveRefCntTypes; +using IntrusiveRefCntTypes = + ::testing::Types<SimpleRefCounted<RefCountedBase>, + SimpleRefCounted<ThreadSafeRefCountedBase>>; TYPED_TEST_SUITE(IntrusiveRefCntPtrTest, IntrusiveRefCntTypes, ); TYPED_TEST(IntrusiveRefCntPtrTest, RefCountedBaseCopyDoesNotLeak) { diff --git a/llvm/unittests/ADT/IteratorTest.cpp b/llvm/unittests/ADT/IteratorTest.cpp index b5d63ef..9dd8c1a 100644 --- a/llvm/unittests/ADT/IteratorTest.cpp +++ b/llvm/unittests/ADT/IteratorTest.cpp @@ -177,8 +177,8 @@ TEST(PointeeIteratorTest, Basic) { V.push_back(&arr[2]); V.push_back(&arr[3]); - typedef pointee_iterator<SmallVectorImpl<int *>::const_iterator> - test_iterator; + using test_iterator = + pointee_iterator<SmallVectorImpl<int *>::const_iterator>; test_iterator Begin, End; Begin = V.begin(); @@ -218,9 +218,8 @@ TEST(PointeeIteratorTest, SmartPointer) { V.push_back(std::make_unique<int>(3)); V.push_back(std::make_unique<int>(4)); - typedef pointee_iterator< - SmallVectorImpl<std::unique_ptr<int>>::const_iterator> - test_iterator; + using test_iterator = + pointee_iterator<SmallVectorImpl<std::unique_ptr<int>>::const_iterator>; test_iterator Begin, End; Begin = V.begin(); diff --git a/llvm/unittests/ADT/PointerSumTypeTest.cpp b/llvm/unittests/ADT/PointerSumTypeTest.cpp index fbf59f3..11e657a 100644 --- a/llvm/unittests/ADT/PointerSumTypeTest.cpp +++ b/llvm/unittests/ADT/PointerSumTypeTest.cpp @@ -17,10 +17,9 @@ struct PointerSumTypeTest : public testing::Test { float f; int i1, i2; - typedef PointerSumType<Kinds, PointerSumTypeMember<Float, float *>, - PointerSumTypeMember<Int1, int *>, - PointerSumTypeMember<Int2, int *>> - SumType; + using SumType = PointerSumType<Kinds, PointerSumTypeMember<Float, float *>, + PointerSumTypeMember<Int1, int *>, + PointerSumTypeMember<Int2, int *>>; SumType a, b, c, n; PointerSumTypeTest() diff --git a/llvm/unittests/ADT/PointerUnionTest.cpp b/llvm/unittests/ADT/PointerUnionTest.cpp index acddb78..d8ac3ae 100644 --- a/llvm/unittests/ADT/PointerUnionTest.cpp +++ b/llvm/unittests/ADT/PointerUnionTest.cpp @@ -12,9 +12,9 @@ using namespace llvm; namespace { -typedef PointerUnion<int *, float *> PU; -typedef PointerUnion<int *, float *, long long *> PU3; -typedef PointerUnion<int *, float *, long long *, double *> PU4; +using PU = PointerUnion<int *, float *>; +using PU3 = PointerUnion<int *, float *, long long *>; +using PU4 = PointerUnion<int *, float *, long long *, double *>; struct PointerUnionTest : public testing::Test { float f; @@ -116,9 +116,9 @@ TEST_F(PointerUnionTest, Get) { template<int I> struct alignas(8) Aligned {}; -typedef PointerUnion<Aligned<0> *, Aligned<1> *, Aligned<2> *, Aligned<3> *, - Aligned<4> *, Aligned<5> *, Aligned<6> *, Aligned<7> *> - PU8; +using PU8 = + PointerUnion<Aligned<0> *, Aligned<1> *, Aligned<2> *, Aligned<3> *, + Aligned<4> *, Aligned<5> *, Aligned<6> *, Aligned<7> *>; TEST_F(PointerUnionTest, ManyElements) { Aligned<0> a0; diff --git a/llvm/unittests/ADT/PostOrderIteratorTest.cpp b/llvm/unittests/ADT/PostOrderIteratorTest.cpp index 838481f..e875dd6 100644 --- a/llvm/unittests/ADT/PostOrderIteratorTest.cpp +++ b/llvm/unittests/ADT/PostOrderIteratorTest.cpp @@ -23,7 +23,7 @@ namespace { // Whether we're able to compile TEST(PostOrderIteratorTest, Compiles) { - typedef SmallPtrSet<void *, 4> ExtSetTy; + using ExtSetTy = SmallPtrSet<void *, 4>; // Tests that template specializations are kept up to date void *Null = nullptr; diff --git a/llvm/unittests/ADT/PriorityWorklistTest.cpp b/llvm/unittests/ADT/PriorityWorklistTest.cpp index f12d32a..08a4773 100644 --- a/llvm/unittests/ADT/PriorityWorklistTest.cpp +++ b/llvm/unittests/ADT/PriorityWorklistTest.cpp @@ -20,8 +20,8 @@ namespace { using namespace llvm; template <typename T> class PriorityWorklistTest : public ::testing::Test {}; -typedef ::testing::Types<PriorityWorklist<int>, SmallPriorityWorklist<int, 2>> - TestTypes; +using TestTypes = + ::testing::Types<PriorityWorklist<int>, SmallPriorityWorklist<int, 2>>; TYPED_TEST_SUITE(PriorityWorklistTest, TestTypes, ); TYPED_TEST(PriorityWorklistTest, Basic) { diff --git a/llvm/unittests/ADT/RangeAdapterTest.cpp b/llvm/unittests/ADT/RangeAdapterTest.cpp index c1a8a98..6849ccbc 100644 --- a/llvm/unittests/ADT/RangeAdapterTest.cpp +++ b/llvm/unittests/ADT/RangeAdapterTest.cpp @@ -24,8 +24,8 @@ class ReverseOnlyVector { public: ReverseOnlyVector(std::initializer_list<int> list) : Vec(list) {} - typedef std::vector<int>::reverse_iterator reverse_iterator; - typedef std::vector<int>::const_reverse_iterator const_reverse_iterator; + using reverse_iterator = std::vector<int>::reverse_iterator; + using const_reverse_iterator = std::vector<int>::const_reverse_iterator; reverse_iterator rbegin() { return Vec.rbegin(); } reverse_iterator rend() { return Vec.rend(); } const_reverse_iterator rbegin() const { return Vec.rbegin(); } @@ -41,11 +41,11 @@ class BidirectionalVector { public: BidirectionalVector(std::initializer_list<int> list) : Vec(list) {} - typedef std::vector<int>::iterator iterator; + using iterator = std::vector<int>::iterator; iterator begin() const; iterator end() const; - typedef std::vector<int>::reverse_iterator reverse_iterator; + using reverse_iterator = std::vector<int>::reverse_iterator; reverse_iterator rbegin() const { return Vec.rbegin(); } reverse_iterator rend() const { return Vec.rend(); } }; @@ -58,15 +58,15 @@ class BidirectionalVectorConsts { public: BidirectionalVectorConsts(std::initializer_list<int> list) : Vec(list) {} - typedef std::vector<int>::iterator iterator; - typedef std::vector<int>::const_iterator const_iterator; + using iterator = std::vector<int>::iterator; + using const_iterator = std::vector<int>::const_iterator; iterator begin(); iterator end(); const_iterator begin() const; const_iterator end() const; - typedef std::vector<int>::reverse_iterator reverse_iterator; - typedef std::vector<int>::const_reverse_iterator const_reverse_iterator; + using reverse_iterator = std::vector<int>::reverse_iterator; + using const_reverse_iterator = std::vector<int>::const_reverse_iterator; reverse_iterator rbegin() { return Vec.rbegin(); } reverse_iterator rend() { return Vec.rend(); } const_reverse_iterator rbegin() const { return Vec.rbegin(); } @@ -80,7 +80,7 @@ class CustomIteratorVector { public: CustomIteratorVector(std::initializer_list<int> list) : V(list) {} - typedef std::vector<int>::iterator iterator; + using iterator = std::vector<int>::iterator; class reverse_iterator { std::vector<int>::iterator I; @@ -126,8 +126,8 @@ template <typename R> void TestRev(const R &r) { // Test fixture template <typename T> class RangeAdapterLValueTest : public ::testing::Test {}; -typedef ::testing::Types<std::vector<int>, std::list<int>, int[4]> - RangeAdapterLValueTestTypes; +using RangeAdapterLValueTestTypes = + ::testing::Types<std::vector<int>, std::list<int>, int[4]>; TYPED_TEST_SUITE(RangeAdapterLValueTest, RangeAdapterLValueTestTypes, ); TYPED_TEST(RangeAdapterLValueTest, TrivialOperation) { @@ -140,10 +140,10 @@ TYPED_TEST(RangeAdapterLValueTest, TrivialOperation) { template <typename T> struct RangeAdapterRValueTest : testing::Test {}; -typedef ::testing::Types<std::vector<int>, std::list<int>, CustomIteratorVector, - ReverseOnlyVector, BidirectionalVector, - BidirectionalVectorConsts> - RangeAdapterRValueTestTypes; +using RangeAdapterRValueTestTypes = + ::testing::Types<std::vector<int>, std::list<int>, CustomIteratorVector, + ReverseOnlyVector, BidirectionalVector, + BidirectionalVectorConsts>; TYPED_TEST_SUITE(RangeAdapterRValueTest, RangeAdapterRValueTestTypes, ); TYPED_TEST(RangeAdapterRValueTest, TrivialOperation) { diff --git a/llvm/unittests/ADT/SCCIteratorTest.cpp b/llvm/unittests/ADT/SCCIteratorTest.cpp index 4835095..5f08829 100644 --- a/llvm/unittests/ADT/SCCIteratorTest.cpp +++ b/llvm/unittests/ADT/SCCIteratorTest.cpp @@ -21,7 +21,7 @@ TEST(SCCIteratorTest, AllSmallGraphs) { // create graphs for which every node has a self-edge. #define NUM_NODES 4 #define NUM_GRAPHS (NUM_NODES * (NUM_NODES - 1)) - typedef Graph<NUM_NODES> GT; + using GT = Graph<NUM_NODES>; /// Enumerate all graphs using NUM_GRAPHS bits. static_assert(NUM_GRAPHS < sizeof(unsigned) * CHAR_BIT, "Too many graphs!"); diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp index 966b1f0..8556777 100644 --- a/llvm/unittests/ADT/STLExtrasTest.cpp +++ b/llvm/unittests/ADT/STLExtrasTest.cpp @@ -60,7 +60,7 @@ TEST(STLExtrasTest, EnumerateLValue) { // Test that a simple LValue can be enumerated and gives correct results with // multiple types, including the empty container. std::vector<char> foo = {'a', 'b', 'c'}; - typedef std::pair<std::size_t, char> CharPairType; + using CharPairType = std::pair<std::size_t, char>; std::vector<CharPairType> CharResults; for (auto [index, value] : llvm::enumerate(foo)) { @@ -72,7 +72,7 @@ TEST(STLExtrasTest, EnumerateLValue) { CharPairType(2u, 'c'))); // Test a const range of a different type. - typedef std::pair<std::size_t, int> IntPairType; + using IntPairType = std::pair<std::size_t, int>; std::vector<IntPairType> IntResults; const std::vector<int> bar = {1, 2, 3}; for (auto [index, value] : llvm::enumerate(bar)) { @@ -111,7 +111,7 @@ TEST(STLExtrasTest, EnumerateModifyLValue) { TEST(STLExtrasTest, EnumerateRValueRef) { // Test that an rvalue can be enumerated. - typedef std::pair<std::size_t, int> PairType; + using PairType = std::pair<std::size_t, int>; std::vector<PairType> Results; auto Enumerator = llvm::enumerate(std::vector<int>{1, 2, 3}); @@ -138,7 +138,7 @@ TEST(STLExtrasTest, EnumerateModifyRValue) { // Test that when enumerating an rvalue, modification still works (even if // this isn't terribly useful, it at least shows that we haven't snuck an // extra const in there somewhere. - typedef std::pair<std::size_t, char> PairType; + using PairType = std::pair<std::size_t, char>; std::vector<PairType> Results; for (auto X : llvm::enumerate(std::vector<char>{'1', '2', '3'})) { diff --git a/llvm/unittests/ADT/SimpleIListTest.cpp b/llvm/unittests/ADT/SimpleIListTest.cpp index c2992ba..cf3df8c 100644 --- a/llvm/unittests/ADT/SimpleIListTest.cpp +++ b/llvm/unittests/ADT/SimpleIListTest.cpp @@ -605,8 +605,8 @@ struct Tag2 {}; struct DoubleNode : ilist_node<DoubleNode, ilist_tag<Tag1>>, ilist_node<DoubleNode, ilist_tag<Tag2>> { - typedef ilist_node<DoubleNode, ilist_tag<Tag1>> Node1Type; - typedef ilist_node<DoubleNode, ilist_tag<Tag2>> Node2Type; + using Node1Type = ilist_node<DoubleNode, ilist_tag<Tag1>>; + using Node2Type = ilist_node<DoubleNode, ilist_tag<Tag2>>; Node1Type::self_iterator getIterator1() { return Node1Type::getIterator(); } Node2Type::self_iterator getIterator2() { return Node2Type::getIterator(); } @@ -617,8 +617,8 @@ struct DoubleNode : ilist_node<DoubleNode, ilist_tag<Tag1>>, return Node2Type::getIterator(); } }; -typedef simple_ilist<DoubleNode, ilist_tag<Tag1>> TaggedList1Type; -typedef simple_ilist<DoubleNode, ilist_tag<Tag2>> TaggedList2Type; +using TaggedList1Type = simple_ilist<DoubleNode, ilist_tag<Tag1>>; +using TaggedList2Type = simple_ilist<DoubleNode, ilist_tag<Tag2>>; TEST(SimpleIListTest, TaggedLists) { TaggedList1Type L1; diff --git a/llvm/unittests/ADT/SmallPtrSetTest.cpp b/llvm/unittests/ADT/SmallPtrSetTest.cpp index a627091..fe7a827 100644 --- a/llvm/unittests/ADT/SmallPtrSetTest.cpp +++ b/llvm/unittests/ADT/SmallPtrSetTest.cpp @@ -57,7 +57,7 @@ TEST(SmallPtrSetTest, GrowthTest) { SmallPtrSet<int *, 4> s; - typedef SmallPtrSet<int *, 4>::iterator iter; + using iter = SmallPtrSet<int *, 4>::iterator; s.insert(&buf[0]); s.insert(&buf[1]); diff --git a/llvm/unittests/ADT/SmallStringTest.cpp b/llvm/unittests/ADT/SmallStringTest.cpp index 2f4df8a..db85824 100644 --- a/llvm/unittests/ADT/SmallStringTest.cpp +++ b/llvm/unittests/ADT/SmallStringTest.cpp @@ -23,7 +23,7 @@ namespace { // Test fixture class class SmallStringTest : public testing::Test { protected: - typedef SmallString<40> StringType; + using StringType = SmallString<40>; StringType theString; diff --git a/llvm/unittests/ADT/SmallVectorTest.cpp b/llvm/unittests/ADT/SmallVectorTest.cpp index 74fc737..dbc626d 100644 --- a/llvm/unittests/ADT/SmallVectorTest.cpp +++ b/llvm/unittests/ADT/SmallVectorTest.cpp @@ -226,13 +226,10 @@ protected: VectorT otherVector; }; - -typedef ::testing::Types<SmallVector<Constructable, 0>, - SmallVector<Constructable, 1>, - SmallVector<Constructable, 2>, - SmallVector<Constructable, 4>, - SmallVector<Constructable, 5> - > SmallVectorTestTypes; +using SmallVectorTestTypes = ::testing::Types< + SmallVector<Constructable, 0>, SmallVector<Constructable, 1>, + SmallVector<Constructable, 2>, SmallVector<Constructable, 4>, + SmallVector<Constructable, 5>>; TYPED_TEST_SUITE(SmallVectorTest, SmallVectorTestTypes, ); // Constructor test. @@ -537,11 +534,11 @@ TYPED_TEST(SmallVectorTest, AppendNonIterTest) { } struct output_iterator { - typedef std::output_iterator_tag iterator_category; - typedef int value_type; - typedef int difference_type; - typedef value_type *pointer; - typedef value_type &reference; + using iterator_category = std::output_iterator_tag; + using value_type = int; + using difference_type = int; + using pointer = value_type *; + using reference = value_type &; operator int() { return 2; } operator Constructable() { return 7; } }; @@ -896,7 +893,7 @@ protected: VectorT2 otherVector; }; -typedef ::testing::Types< +using DualSmallVectorTestTypes = ::testing::Types< // Small mode -> Small mode. std::pair<SmallVector<Constructable, 4>, SmallVector<Constructable, 4>>, // Small mode -> Big mode. @@ -904,8 +901,7 @@ typedef ::testing::Types< // Big mode -> Small mode. std::pair<SmallVector<Constructable, 2>, SmallVector<Constructable, 4>>, // Big mode -> Big mode. - std::pair<SmallVector<Constructable, 2>, SmallVector<Constructable, 2>> - > DualSmallVectorTestTypes; + std::pair<SmallVector<Constructable, 2>, SmallVector<Constructable, 2>>>; TYPED_TEST_SUITE(DualSmallVectorsTest, DualSmallVectorTestTypes, ); diff --git a/llvm/unittests/ADT/SparseMultiSetTest.cpp b/llvm/unittests/ADT/SparseMultiSetTest.cpp index 54f7bc99..91d37f4 100644 --- a/llvm/unittests/ADT/SparseMultiSetTest.cpp +++ b/llvm/unittests/ADT/SparseMultiSetTest.cpp @@ -13,7 +13,7 @@ using namespace llvm; namespace { -typedef SparseMultiSet<unsigned> USet; +using USet = SparseMultiSet<unsigned>; // Empty set tests. TEST(SparseMultiSetTest, EmptySet) { @@ -211,7 +211,7 @@ struct Alt { }; TEST(SparseMultiSetTest, AltStructSet) { - typedef SparseMultiSet<Alt> ASet; + using ASet = SparseMultiSet<Alt>; ASet Set; Set.setUniverse(10); Set.insert(Alt(1005)); diff --git a/llvm/unittests/ADT/SparseSetTest.cpp b/llvm/unittests/ADT/SparseSetTest.cpp index 4fbf1ca..f2b9329 100644 --- a/llvm/unittests/ADT/SparseSetTest.cpp +++ b/llvm/unittests/ADT/SparseSetTest.cpp @@ -13,7 +13,7 @@ using namespace llvm; namespace { -typedef SparseSet<unsigned> USet; +using USet = SparseSet<unsigned>; // Empty set tests. TEST(SparseSetTest, EmptySet) { @@ -166,7 +166,7 @@ struct Alt { }; TEST(SparseSetTest, AltStructSet) { - typedef SparseSet<Alt> ASet; + using ASet = SparseSet<Alt>; ASet Set; Set.setUniverse(10); Set.insert(Alt(1005)); diff --git a/llvm/unittests/ADT/StringSwitchTest.cpp b/llvm/unittests/ADT/StringSwitchTest.cpp index c94feb5..75d50f4 100644 --- a/llvm/unittests/ADT/StringSwitchTest.cpp +++ b/llvm/unittests/ADT/StringSwitchTest.cpp @@ -240,6 +240,23 @@ TEST(StringSwitchTest, CasesCopies) { EXPECT_EQ(NumCopies, 1u); } +TEST(StringSwitchTest, StringSwitchMultipleMatches) { + auto Translate = [](StringRef S) { + return llvm::StringSwitch<int>(S) + .CaseLower("A", 0) + .Case("b", 1) + .Case("a", 2) + .CasesLower({"a", "b"}, 3) + .DefaultUnreachable(); + }; + + // Check that the value of the first match is returned. + EXPECT_EQ(0, Translate("A")); + EXPECT_EQ(0, Translate("a")); + EXPECT_EQ(3, Translate("B")); + EXPECT_EQ(1, Translate("b")); +} + TEST(StringSwitchTest, DefaultUnreachable) { auto Translate = [](StringRef S) { return llvm::StringSwitch<int>(S) diff --git a/llvm/unittests/ADT/TestGraph.h b/llvm/unittests/ADT/TestGraph.h index a59ab50..bb2ec47 100644 --- a/llvm/unittests/ADT/TestGraph.h +++ b/llvm/unittests/ADT/TestGraph.h @@ -34,7 +34,7 @@ public: /// NodeSubset - A subset of the graph's nodes. class NodeSubset { - typedef unsigned char BitVector; // Where the limitation N <= 8 comes from. + using BitVector = unsigned char; // Where the limitation N <= 8 comes from. BitVector Elements; NodeSubset(BitVector e) : Elements(e) {} public: @@ -96,7 +96,7 @@ public: }; /// NodeType - Node index and set of children of the node. - typedef std::pair<unsigned, NodeSubset> NodeType; + using NodeType = std::pair<unsigned, NodeSubset>; private: /// Nodes - The list of nodes for this graph. @@ -233,8 +233,8 @@ public: template <unsigned N> struct GraphTraits<Graph<N> > { - typedef typename Graph<N>::NodeType *NodeRef; - typedef typename Graph<N>::ChildIterator ChildIteratorType; + using NodeRef = typename Graph<N>::NodeType *; + using ChildIteratorType = typename Graph<N>::ChildIterator; static NodeRef getEntryNode(const Graph<N> &G) { return G.AccessNode(0); } static ChildIteratorType child_begin(NodeRef Node) { diff --git a/llvm/unittests/ADT/TinyPtrVectorTest.cpp b/llvm/unittests/ADT/TinyPtrVectorTest.cpp index af4ae4f..c77721d 100644 --- a/llvm/unittests/ADT/TinyPtrVectorTest.cpp +++ b/llvm/unittests/ADT/TinyPtrVectorTest.cpp @@ -28,14 +28,14 @@ template <typename PointerTy, unsigned IntBits, typename IntType, typename PtrTraits, typename Info> struct RemovePointer< PointerIntPair<PointerTy, IntBits, IntType, PtrTraits, Info>> { - typedef typename RemovePointer<PointerTy>::type type; + using type = typename RemovePointer<PointerTy>::type; }; template <typename VectorT> class TinyPtrVectorTest : public testing::Test { protected: - typedef typename VectorT::value_type PtrT; - typedef typename RemovePointer<PtrT>::type ValueT; + using PtrT = typename VectorT::value_type; + using ValueT = typename RemovePointer<PtrT>::type; using PtrTraits = PointerLikeTypeTraits<PtrT>; VectorT V; @@ -78,9 +78,9 @@ protected: } }; -typedef ::testing::Types<TinyPtrVector<int *>, TinyPtrVector<double *>, - TinyPtrVector<PointerIntPair<int *, 1>>> - TinyPtrVectorTestTypes; +using TinyPtrVectorTestTypes = + ::testing::Types<TinyPtrVector<int *>, TinyPtrVector<double *>, + TinyPtrVector<PointerIntPair<int *, 1>>>; TYPED_TEST_SUITE(TinyPtrVectorTest, TinyPtrVectorTestTypes, ); TYPED_TEST(TinyPtrVectorTest, EmptyTest) { diff --git a/llvm/unittests/CAS/ActionCacheTest.cpp b/llvm/unittests/CAS/ActionCacheTest.cpp index db67e30..692da23 100644 --- a/llvm/unittests/CAS/ActionCacheTest.cpp +++ b/llvm/unittests/CAS/ActionCacheTest.cpp @@ -21,7 +21,7 @@ using namespace llvm; using namespace llvm::cas; TEST_P(CASTest, ActionCacheHit) { - std::shared_ptr<ObjectStore> CAS = createObjectStore(); + std::unique_ptr<ObjectStore> CAS = createObjectStore(); std::unique_ptr<ActionCache> Cache = createActionCache(); std::optional<ObjectProxy> ID; @@ -36,7 +36,7 @@ TEST_P(CASTest, ActionCacheHit) { } TEST_P(CASTest, ActionCacheMiss) { - std::shared_ptr<ObjectStore> CAS = createObjectStore(); + std::unique_ptr<ObjectStore> CAS = createObjectStore(); std::unique_ptr<ActionCache> Cache = createActionCache(); std::optional<ObjectProxy> ID1, ID2; @@ -59,7 +59,7 @@ TEST_P(CASTest, ActionCacheMiss) { } TEST_P(CASTest, ActionCacheRewrite) { - std::shared_ptr<ObjectStore> CAS = createObjectStore(); + std::unique_ptr<ObjectStore> CAS = createObjectStore(); std::unique_ptr<ActionCache> Cache = createActionCache(); std::optional<ObjectProxy> ID1, ID2; diff --git a/llvm/unittests/CAS/BuiltinUnifiedCASDatabasesTest.cpp b/llvm/unittests/CAS/BuiltinUnifiedCASDatabasesTest.cpp new file mode 100644 index 0000000..19522e9 --- /dev/null +++ b/llvm/unittests/CAS/BuiltinUnifiedCASDatabasesTest.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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/CAS/BuiltinUnifiedCASDatabases.h" +#include "CASTestConfig.h" +#include "llvm/CAS/ActionCache.h" +#include "llvm/CAS/ObjectStore.h" +#include "llvm/Testing/Support/Error.h" +#include "llvm/Testing/Support/SupportHelpers.h" +#include "gtest/gtest.h" + +using namespace llvm; +using namespace llvm::cas; + +TEST_F(OnDiskCASTest, UnifiedCASMaterializationCheckPreventsGarbageCollection) { + unittest::TempDir Temp("on-disk-unified-cas", /*Unique=*/true); + + auto WithCAS = [&](llvm::function_ref<void(ObjectStore &)> Action) { + std::pair<std::unique_ptr<ObjectStore>, std::unique_ptr<ActionCache>> DBs; + ASSERT_THAT_ERROR( + createOnDiskUnifiedCASDatabases(Temp.path()).moveInto(DBs), + Succeeded()); + ObjectStore &CAS = *DBs.first; + ASSERT_THAT_ERROR(CAS.setSizeLimit(1), Succeeded()); + Action(CAS); + }; + + std::optional<CASID> ID; + + // Create an object in the CAS. + WithCAS([&ID](ObjectStore &CAS) { + std::optional<ObjectRef> Ref; + ASSERT_THAT_ERROR(CAS.store({}, "blah").moveInto(Ref), Succeeded()); + ASSERT_TRUE(Ref.has_value()); + + ID = CAS.getID(*Ref); + }); + + // Check materialization and prune the storage. + WithCAS([&ID](ObjectStore &CAS) { + std::optional<ObjectRef> Ref = CAS.getReference(*ID); + ASSERT_TRUE(Ref.has_value()); + + std::optional<bool> IsMaterialized; + ASSERT_THAT_ERROR(CAS.isMaterialized(*Ref).moveInto(IsMaterialized), + Succeeded()); + ASSERT_TRUE(IsMaterialized); + + ASSERT_THAT_ERROR(CAS.pruneStorageData(), Succeeded()); + }); + + // Verify that the previous materialization check kept the object in the CAS. + WithCAS([&ID](ObjectStore &CAS) { + std::optional<ObjectRef> Ref = CAS.getReference(*ID); + ASSERT_TRUE(Ref.has_value()); + + std::optional<bool> IsMaterialized; + ASSERT_THAT_ERROR(CAS.isMaterialized(*Ref).moveInto(IsMaterialized), + Succeeded()); + ASSERT_TRUE(IsMaterialized); + }); +} diff --git a/llvm/unittests/CAS/CASTestConfig.cpp b/llvm/unittests/CAS/CASTestConfig.cpp index 10e4b68..08cbf1d 100644 --- a/llvm/unittests/CAS/CASTestConfig.cpp +++ b/llvm/unittests/CAS/CASTestConfig.cpp @@ -8,6 +8,7 @@ #include "CASTestConfig.h" #include "llvm/CAS/ObjectStore.h" +#include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" #include <mutex> @@ -15,7 +16,8 @@ using namespace llvm; using namespace llvm::cas; static CASTestingEnv createInMemory(int I) { - return CASTestingEnv{createInMemoryCAS(), createInMemoryActionCache()}; + return CASTestingEnv{createInMemoryCAS(), createInMemoryActionCache(), + std::nullopt}; } INSTANTIATE_TEST_SUITE_P(InMemoryCAS, CASTest, @@ -23,7 +25,7 @@ INSTANTIATE_TEST_SUITE_P(InMemoryCAS, CASTest, #if LLVM_ENABLE_ONDISK_CAS namespace llvm::cas::ondisk { -extern void setMaxMappingSize(uint64_t Size); +void setMaxMappingSize(uint64_t Size); } // namespace llvm::cas::ondisk void setMaxOnDiskCASMappingSize() { @@ -31,6 +33,17 @@ void setMaxOnDiskCASMappingSize() { std::call_once( Flag, [] { llvm::cas::ondisk::setMaxMappingSize(100 * 1024 * 1024); }); } + +static CASTestingEnv createOnDisk(int I) { + unittest::TempDir Temp("on-disk-cas", /*Unique=*/true); + std::unique_ptr<ObjectStore> CAS; + EXPECT_THAT_ERROR(createOnDiskCAS(Temp.path()).moveInto(CAS), Succeeded()); + std::unique_ptr<ActionCache> Cache; + EXPECT_THAT_ERROR(createOnDiskActionCache(Temp.path()).moveInto(Cache), + Succeeded()); + return CASTestingEnv{std::move(CAS), std::move(Cache), std::move(Temp)}; +} +INSTANTIATE_TEST_SUITE_P(OnDiskCAS, CASTest, ::testing::Values(createOnDisk)); #else void setMaxOnDiskCASMappingSize() {} #endif /* LLVM_ENABLE_ONDISK_CAS */ diff --git a/llvm/unittests/CAS/CASTestConfig.h b/llvm/unittests/CAS/CASTestConfig.h index 8d3c553..b1c0e59 100644 --- a/llvm/unittests/CAS/CASTestConfig.h +++ b/llvm/unittests/CAS/CASTestConfig.h @@ -6,16 +6,28 @@ // //===----------------------------------------------------------------------===// +#ifndef LLVM_UNITTESTS_CASTESTCONFIG_H +#define LLVM_UNITTESTS_CASTESTCONFIG_H + #include "llvm/CAS/ActionCache.h" #include "llvm/CAS/ObjectStore.h" +#include "llvm/Testing/Support/SupportHelpers.h" #include "gtest/gtest.h" +#include <memory> -#ifndef LLVM_UNITTESTS_CASTESTCONFIG_H -#define LLVM_UNITTESTS_CASTESTCONFIG_H +namespace llvm::unittest::cas { +class MockEnv { + void anchor(); + +public: + virtual ~MockEnv(); +}; +} // namespace llvm::unittest::cas struct CASTestingEnv { std::unique_ptr<llvm::cas::ObjectStore> CAS; std::unique_ptr<llvm::cas::ActionCache> Cache; + std::optional<llvm::unittest::TempDir> Temp; }; void setMaxOnDiskCASMappingSize(); @@ -24,26 +36,47 @@ void setMaxOnDiskCASMappingSize(); class OnDiskCASTest : public ::testing::Test { protected: void SetUp() override { +#if !LLVM_ENABLE_ONDISK_CAS + GTEST_SKIP() << "OnDiskCAS is not enabled"; +#endif // Use a smaller database size for testing to conserve disk space. setMaxOnDiskCASMappingSize(); } }; +// Parametered test fixture for ObjectStore and ActionCache tests. class CASTest : public testing::TestWithParam<std::function<CASTestingEnv(int)>> { protected: std::optional<int> NextCASIndex; + llvm::SmallVector<llvm::unittest::TempDir> Dirs; + + llvm::SmallVector<std::unique_ptr<llvm::unittest::cas::MockEnv>> Envs; + std::unique_ptr<llvm::cas::ObjectStore> createObjectStore() { auto TD = GetParam()(++(*NextCASIndex)); + if (TD.Temp) + Dirs.push_back(std::move(*TD.Temp)); return std::move(TD.CAS); } std::unique_ptr<llvm::cas::ActionCache> createActionCache() { auto TD = GetParam()(++(*NextCASIndex)); + if (TD.Temp) + Dirs.push_back(std::move(*TD.Temp)); return std::move(TD.Cache); } - void SetUp() override { NextCASIndex = 0; } - void TearDown() override { NextCASIndex = std::nullopt; } + + void SetUp() override { + NextCASIndex = 0; + setMaxOnDiskCASMappingSize(); + } + + void TearDown() override { + NextCASIndex = std::nullopt; + Dirs.clear(); + Envs.clear(); + } }; #endif diff --git a/llvm/unittests/CAS/CMakeLists.txt b/llvm/unittests/CAS/CMakeLists.txt index da469f7..91e49be 100644 --- a/llvm/unittests/CAS/CMakeLists.txt +++ b/llvm/unittests/CAS/CMakeLists.txt @@ -1,9 +1,11 @@ set(ONDISK_CAS_TEST_SOURCES + BuiltinUnifiedCASDatabasesTest.cpp OnDiskGraphDBTest.cpp OnDiskDataAllocatorTest.cpp OnDiskKeyValueDBTest.cpp OnDiskTrieRawHashMapTest.cpp ProgramTest.cpp + UnifiedOnDiskCacheTest.cpp ) set(LLVM_OPTIONAL_SOURCES diff --git a/llvm/unittests/CAS/ObjectStoreTest.cpp b/llvm/unittests/CAS/ObjectStoreTest.cpp index 54083fd..b43ae33 100644 --- a/llvm/unittests/CAS/ObjectStoreTest.cpp +++ b/llvm/unittests/CAS/ObjectStoreTest.cpp @@ -1,4 +1,4 @@ -//===- ObjectStoreTest.cpp ------------------------------------------------===// +//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -76,7 +76,7 @@ multiline text multiline text multiline text multiline text multiline text)", // Run validation on all CASIDs. for (int I = 0, E = IDs.size(); I != E; ++I) - ASSERT_THAT_ERROR(CAS1->validate(IDs[I]), Succeeded()); + ASSERT_THAT_ERROR(CAS1->validateObject(IDs[I]), Succeeded()); // Check that the blobs can be retrieved multiple times. for (int I = 0, E = IDs.size(); I != E; ++I) { @@ -120,15 +120,15 @@ TEST_P(CASTest, BlobsBig) { std::optional<CASID> ID2; ASSERT_THAT_ERROR(CAS->createProxy({}, String1).moveInto(ID1), Succeeded()); ASSERT_THAT_ERROR(CAS->createProxy({}, String1).moveInto(ID2), Succeeded()); - ASSERT_THAT_ERROR(CAS->validate(*ID1), Succeeded()); - ASSERT_THAT_ERROR(CAS->validate(*ID2), Succeeded()); + ASSERT_THAT_ERROR(CAS->validateObject(*ID1), Succeeded()); + ASSERT_THAT_ERROR(CAS->validateObject(*ID2), Succeeded()); ASSERT_EQ(ID1, ID2); String1.append(String2); ASSERT_THAT_ERROR(CAS->createProxy({}, String2).moveInto(ID1), Succeeded()); ASSERT_THAT_ERROR(CAS->createProxy({}, String2).moveInto(ID2), Succeeded()); - ASSERT_THAT_ERROR(CAS->validate(*ID1), Succeeded()); - ASSERT_THAT_ERROR(CAS->validate(*ID2), Succeeded()); + ASSERT_THAT_ERROR(CAS->validateObject(*ID1), Succeeded()); + ASSERT_THAT_ERROR(CAS->validateObject(*ID2), Succeeded()); ASSERT_EQ(ID1, ID2); String2.append(String1); } @@ -176,10 +176,11 @@ multiline text multiline text multiline text multiline text multiline text)", // Check basic printing of IDs. IDs.push_back(CAS1->getID(*Node)); - auto ID = CAS1->getID(Nodes.back()); - EXPECT_EQ(ID.toString(), IDs.back().toString()); - EXPECT_EQ(*Node, Nodes.back()); - EXPECT_EQ(ID, IDs.back()); + EXPECT_EQ(IDs.back().toString(), IDs.back().toString()); + EXPECT_EQ(Nodes.front(), Nodes.front()); + EXPECT_EQ(Nodes.back(), Nodes.back()); + EXPECT_EQ(IDs.front(), IDs.front()); + EXPECT_EQ(IDs.back(), IDs.back()); if (Nodes.size() <= 1) continue; EXPECT_NE(Nodes.front(), Nodes.back()); @@ -266,7 +267,7 @@ TEST_P(CASTest, NodesBig) { } for (auto ID : CreatedNodes) - ASSERT_THAT_ERROR(CAS->validate(CAS->getID(ID)), Succeeded()); + ASSERT_THAT_ERROR(CAS->validateObject(CAS->getID(ID)), Succeeded()); } #if LLVM_ENABLE_THREADS @@ -332,17 +333,124 @@ static void testBlobsParallel1(ObjectStore &CAS, uint64_t BlobSize) { } TEST_P(CASTest, BlobsParallel) { - std::shared_ptr<ObjectStore> CAS = createObjectStore(); + std::unique_ptr<ObjectStore> CAS = createObjectStore(); uint64_t Size = 1ULL * 1024; ASSERT_NO_FATAL_FAILURE(testBlobsParallel1(*CAS, Size)); } #ifdef EXPENSIVE_CHECKS TEST_P(CASTest, BlobsBigParallel) { - std::shared_ptr<ObjectStore> CAS = createObjectStore(); + std::unique_ptr<ObjectStore> CAS = createObjectStore(); // 100k is large enough to be standalone files in our on-disk cas. uint64_t Size = 100ULL * 1024; ASSERT_NO_FATAL_FAILURE(testBlobsParallel1(*CAS, Size)); } #endif // EXPENSIVE_CHECKS + +#ifndef _WIN32 // create_link won't work for directories on Windows +TEST_F(OnDiskCASTest, OnDiskCASBlobsParallelMultiCAS) { + // This test intentionally uses symlinked paths to the same CAS to subvert the + // shared memory mappings that would normally be created within a single + // process. This breaks the lock file guarantees, so we must be careful not + // to create or destroy the CAS objects concurrently, which is when the locks + // are normally important. + unittest::TempDir Temp("on-disk-cas", /*Unique=*/true); + ASSERT_EQ(sys::fs::create_directory(Temp.path("real_cas")), + std::error_code()); + ASSERT_EQ(sys::fs::create_link("real_cas", Temp.path("sym_cas1")), + std::error_code()); + ASSERT_EQ(sys::fs::create_link("real_cas", Temp.path("sym_cas2")), + std::error_code()); + ASSERT_EQ(sys::fs::create_link("real_cas", Temp.path("sym_cas3")), + std::error_code()); + + std::unique_ptr<ObjectStore> CAS1, CAS2, CAS3, CAS4; + ASSERT_THAT_ERROR(createOnDiskCAS(Temp.path("real_cas")).moveInto(CAS1), + Succeeded()); + ASSERT_THAT_ERROR(createOnDiskCAS(Temp.path("sym_cas1")).moveInto(CAS2), + Succeeded()); + ASSERT_THAT_ERROR(createOnDiskCAS(Temp.path("sym_cas2")).moveInto(CAS3), + Succeeded()); + ASSERT_THAT_ERROR(createOnDiskCAS(Temp.path("sym_cas3")).moveInto(CAS4), + Succeeded()); + + uint64_t Size = 1ULL * 1024; + ASSERT_NO_FATAL_FAILURE(testBlobsParallel(*CAS1, *CAS2, *CAS3, *CAS4, Size)); +} + +TEST_F(OnDiskCASTest, OnDiskCASBlobsBigParallelMultiCAS) { + // See comment in BlobsParallelMultiCAS. + unittest::TempDir Temp("on-disk-cas", /*Unique=*/true); + ASSERT_EQ(sys::fs::create_directory(Temp.path("real_cas")), + std::error_code()); + ASSERT_EQ(sys::fs::create_link("real_cas", Temp.path("sym_cas1")), + std::error_code()); + ASSERT_EQ(sys::fs::create_link("real_cas", Temp.path("sym_cas2")), + std::error_code()); + ASSERT_EQ(sys::fs::create_link("real_cas", Temp.path("sym_cas3")), + std::error_code()); + + std::unique_ptr<ObjectStore> CAS1, CAS2, CAS3, CAS4; + ASSERT_THAT_ERROR(createOnDiskCAS(Temp.path("real_cas")).moveInto(CAS1), + Succeeded()); + ASSERT_THAT_ERROR(createOnDiskCAS(Temp.path("sym_cas1")).moveInto(CAS2), + Succeeded()); + ASSERT_THAT_ERROR(createOnDiskCAS(Temp.path("sym_cas2")).moveInto(CAS3), + Succeeded()); + ASSERT_THAT_ERROR(createOnDiskCAS(Temp.path("sym_cas3")).moveInto(CAS4), + Succeeded()); + + // 100k is large enough to be standalone files in our on-disk cas. + uint64_t Size = 100ULL * 1024; + ASSERT_NO_FATAL_FAILURE(testBlobsParallel(*CAS1, *CAS2, *CAS3, *CAS4, Size)); +} +#endif // _WIN32 #endif // LLVM_ENABLE_THREADS + +TEST_F(OnDiskCASTest, OnDiskCASDiskSize) { + unittest::TempDir Temp("on-disk-cas", /*Unique=*/true); + std::unique_ptr<ObjectStore> CAS; + ASSERT_THAT_ERROR(createOnDiskCAS(Temp.path()).moveInto(CAS), Succeeded()); + + uint64_t MaxSize = 100 * 1024 * 1024; + + // Check that we map the files to the correct size. + auto CheckFileSizes = [&](bool Mapped) { + bool FoundIndex = false, FoundData = false; + std::error_code EC; + for (sys::fs::directory_iterator I(Temp.path(), EC), E; I != E && !EC; + I.increment(EC)) { + StringRef Filename = sys::path::filename(I->path()); + if (Filename.starts_with("index.") && !Filename.ends_with(".shared")) { + FoundIndex = true; + ASSERT_TRUE(I->status()); + if (Mapped) + EXPECT_EQ(I->status()->getSize(), MaxSize); + else + EXPECT_LT(I->status()->getSize(), MaxSize); + } + if (Filename.starts_with("data.") && !Filename.ends_with(".shared")) { + FoundData = true; + ASSERT_TRUE(I->status()); + if (Mapped) + EXPECT_EQ(I->status()->getSize(), MaxSize); + else + EXPECT_LT(I->status()->getSize(), MaxSize); + } + } + ASSERT_TRUE(FoundIndex); + ASSERT_TRUE(FoundData); + }; + + // Check that we have the full mapping size when the CAS is open. + CheckFileSizes(/*Mapped=*/true); + CAS.reset(); + // Check that the CAS is shrunk to a smaller size. + CheckFileSizes(/*Mapped=*/false); + + // Repeat the checks when starting from an existing CAS. + ASSERT_THAT_ERROR(createOnDiskCAS(Temp.path()).moveInto(CAS), Succeeded()); + CheckFileSizes(/*Mapped=*/true); + CAS.reset(); + CheckFileSizes(/*Mapped=*/false); +} diff --git a/llvm/unittests/CAS/OnDiskCommonUtils.h b/llvm/unittests/CAS/OnDiskCommonUtils.h index 89f93e0..48a1830 100644 --- a/llvm/unittests/CAS/OnDiskCommonUtils.h +++ b/llvm/unittests/CAS/OnDiskCommonUtils.h @@ -12,6 +12,8 @@ #include "llvm/CAS/BuiltinObjectHasher.h" #include "llvm/CAS/OnDiskGraphDB.h" +#include "llvm/CAS/OnDiskKeyValueDB.h" +#include "llvm/CAS/UnifiedOnDiskCache.h" #include "llvm/Support/BLAKE3.h" #include "llvm/Testing/Support/Error.h" @@ -58,6 +60,25 @@ inline Expected<ObjectID> store(OnDiskGraphDB &DB, StringRef Data, return ID; } +inline Expected<ObjectID> cachePut(OnDiskKeyValueDB &DB, ArrayRef<uint8_t> Key, + ObjectID ID) { + auto Value = UnifiedOnDiskCache::getValueFromObjectID(ID); + auto Result = DB.put(Key, Value); + if (!Result) + return Result.takeError(); + return UnifiedOnDiskCache::getObjectIDFromValue(*Result); +} + +inline Expected<std::optional<ObjectID>> cacheGet(OnDiskKeyValueDB &DB, + ArrayRef<uint8_t> Key) { + auto Result = DB.get(Key); + if (!Result) + return Result.takeError(); + if (!*Result) + return std::nullopt; + return UnifiedOnDiskCache::getObjectIDFromValue(**Result); +} + inline Error printTree(OnDiskGraphDB &DB, ObjectID ID, raw_ostream &OS, unsigned Indent = 0) { std::optional<ondisk::ObjectHandle> Obj; diff --git a/llvm/unittests/CAS/OnDiskGraphDBTest.cpp b/llvm/unittests/CAS/OnDiskGraphDBTest.cpp index 3c2e963..e9c73bf 100644 --- a/llvm/unittests/CAS/OnDiskGraphDBTest.cpp +++ b/llvm/unittests/CAS/OnDiskGraphDBTest.cpp @@ -102,7 +102,7 @@ TEST_F(OnDiskCASTest, OnDiskGraphDBFaultInSingleNode) { std::unique_ptr<OnDiskGraphDB> DB; ASSERT_THAT_ERROR( OnDiskGraphDB::open(Temp.path(), "blake3", sizeof(HashType), - std::move(UpstreamDB), + UpstreamDB.get(), OnDiskGraphDB::FaultInPolicy::SingleNode) .moveInto(DB), Succeeded()); @@ -208,7 +208,7 @@ TEST_F(OnDiskCASTest, OnDiskGraphDBFaultInFullTree) { unittest::TempDir Temp("ondiskcas", /*Unique=*/true); std::unique_ptr<OnDiskGraphDB> DB; ASSERT_THAT_ERROR(OnDiskGraphDB::open(Temp.path(), "blake3", sizeof(HashType), - std::move(UpstreamDB), + UpstreamDB.get(), OnDiskGraphDB::FaultInPolicy::FullTree) .moveInto(DB), Succeeded()); @@ -264,14 +264,14 @@ TEST_F(OnDiskCASTest, OnDiskGraphDBFaultInPolicyConflict) { unittest::TempDir Temp("ondiskcas", /*Unique=*/true); std::unique_ptr<OnDiskGraphDB> DB; ASSERT_THAT_ERROR(OnDiskGraphDB::open(Temp.path(), "blake3", - sizeof(HashType), - std::move(UpstreamDB), Policy1) + sizeof(HashType), UpstreamDB.get(), + Policy1) .moveInto(DB), Succeeded()); DB.reset(); ASSERT_THAT_ERROR(OnDiskGraphDB::open(Temp.path(), "blake3", - sizeof(HashType), - std::move(UpstreamDB), Policy2) + sizeof(HashType), UpstreamDB.get(), + Policy2) .moveInto(DB), Failed()); }; diff --git a/llvm/unittests/CAS/UnifiedOnDiskCacheTest.cpp b/llvm/unittests/CAS/UnifiedOnDiskCacheTest.cpp new file mode 100644 index 0000000..09aebc2 --- /dev/null +++ b/llvm/unittests/CAS/UnifiedOnDiskCacheTest.cpp @@ -0,0 +1,198 @@ +//===----------------------------------------------------------------------===// +// +// 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/CAS/UnifiedOnDiskCache.h" +#include "CASTestConfig.h" +#include "OnDiskCommonUtils.h" +#include "llvm/Testing/Support/Error.h" +#include "llvm/Testing/Support/SupportHelpers.h" +#include "gtest/gtest.h" + +using namespace llvm; +using namespace llvm::cas; +using namespace llvm::cas::ondisk; +using namespace llvm::unittest::cas; + +/// Visits all the files of a directory recursively and returns the sum of their +/// sizes. +static Expected<size_t> countFileSizes(StringRef Path) { + size_t TotalSize = 0; + std::error_code EC; + for (sys::fs::directory_iterator DirI(Path, EC), DirE; !EC && DirI != DirE; + DirI.increment(EC)) { + if (DirI->type() == sys::fs::file_type::directory_file) { + Expected<size_t> Subsize = countFileSizes(DirI->path()); + if (!Subsize) + return Subsize.takeError(); + TotalSize += *Subsize; + continue; + } + ErrorOr<sys::fs::basic_file_status> Stat = DirI->status(); + if (!Stat) + return createFileError(DirI->path(), Stat.getError()); + TotalSize += Stat->getSize(); + } + if (EC) + return createFileError(Path, EC); + return TotalSize; +} + +TEST_F(OnDiskCASTest, UnifiedOnDiskCacheTest) { + unittest::TempDir Temp("ondisk-unified", /*Unique=*/true); + std::unique_ptr<UnifiedOnDiskCache> UniDB; + + const uint64_t SizeLimit = 1024ull * 64; + auto reopenDB = [&]() { + UniDB.reset(); + ASSERT_THAT_ERROR(UnifiedOnDiskCache::open(Temp.path(), SizeLimit, "blake3", + sizeof(HashType)) + .moveInto(UniDB), + Succeeded()); + }; + + reopenDB(); + + HashType RootHash; + HashType OtherHash; + HashType Key1Hash; + HashType Key2Hash; + { + OnDiskGraphDB &DB = UniDB->getGraphDB(); + std::optional<ObjectID> ID1; + ASSERT_THAT_ERROR(store(DB, "1", {}).moveInto(ID1), Succeeded()); + std::optional<ObjectID> ID2; + ASSERT_THAT_ERROR(store(DB, "2", {}).moveInto(ID2), Succeeded()); + std::optional<ObjectID> IDRoot; + ASSERT_THAT_ERROR(store(DB, "root", {*ID1, *ID2}).moveInto(IDRoot), + Succeeded()); + ArrayRef<uint8_t> Digest = DB.getDigest(*IDRoot); + ASSERT_EQ(Digest.size(), RootHash.size()); + llvm::copy(Digest, RootHash.data()); + + std::optional<ObjectID> IDOther; + ASSERT_THAT_ERROR(store(DB, "other", {}).moveInto(IDOther), Succeeded()); + Digest = DB.getDigest(*IDOther); + ASSERT_EQ(Digest.size(), OtherHash.size()); + llvm::copy(Digest, OtherHash.data()); + + Key1Hash = digest("key1"); + std::optional<ObjectID> Val; + ASSERT_THAT_ERROR( + cachePut(UniDB->getKeyValueDB(), Key1Hash, *IDRoot).moveInto(Val), + Succeeded()); + EXPECT_EQ(IDRoot, Val); + + Key2Hash = digest("key2"); + std::optional<ObjectID> KeyID; + ASSERT_THAT_ERROR(DB.getReference(Key2Hash).moveInto(KeyID), Succeeded()); + ASSERT_THAT_ERROR(cachePut(UniDB->getKeyValueDB(), + UniDB->getGraphDB().getDigest(*KeyID), *ID1) + .moveInto(Val), + Succeeded()); + } + + auto checkTree = [&](const HashType &Digest, StringRef ExpectedTree) { + OnDiskGraphDB &DB = UniDB->getGraphDB(); + std::optional<ObjectID> ID; + ASSERT_THAT_ERROR(DB.getReference(Digest).moveInto(ID), Succeeded()); + std::string PrintedTree; + raw_string_ostream OS(PrintedTree); + ASSERT_THAT_ERROR(printTree(DB, *ID, OS), Succeeded()); + EXPECT_EQ(PrintedTree, ExpectedTree); + }; + auto checkRootTree = [&]() { + return checkTree(RootHash, "root\n 1\n 2\n"); + }; + + auto checkKey = [&](const HashType &Key, StringRef ExpectedData) { + OnDiskGraphDB &DB = UniDB->getGraphDB(); + std::optional<ObjectID> Val; + ASSERT_THAT_ERROR(cacheGet(UniDB->getKeyValueDB(), Key).moveInto(Val), + Succeeded()); + + ASSERT_TRUE(Val.has_value()); + std::optional<ondisk::ObjectHandle> Obj; + ASSERT_THAT_ERROR(DB.load(*Val).moveInto(Obj), Succeeded()); + EXPECT_EQ(toStringRef(DB.getObjectData(*Obj)), ExpectedData); + }; + + checkRootTree(); + checkTree(OtherHash, "other\n"); + checkKey(Key1Hash, "root"); + checkKey(Key2Hash, "1"); + + auto storeBigObject = [&](unsigned Index) { + SmallString<1000> Buf; + Buf.append(970, 'a'); + raw_svector_ostream(Buf) << Index; + std::optional<ObjectID> ID; + ASSERT_THAT_ERROR(store(UniDB->getGraphDB(), Buf, {}).moveInto(ID), + Succeeded()); + }; + + uint64_t PrevStoreSize = UniDB->getStorageSize(); + unsigned Index = 0; + while (!UniDB->hasExceededSizeLimit()) { + storeBigObject(Index++); + } + EXPECT_GT(UniDB->getStorageSize(), PrevStoreSize); + UniDB->setSizeLimit(SizeLimit * 2); + EXPECT_FALSE(UniDB->hasExceededSizeLimit()); + UniDB->setSizeLimit(SizeLimit); + EXPECT_TRUE(UniDB->hasExceededSizeLimit()); + + reopenDB(); + + EXPECT_FALSE(UniDB->hasExceededSizeLimit()); + EXPECT_FALSE(UniDB->needsGarbageCollection()); + + checkRootTree(); + checkKey(Key1Hash, "root"); + + while (!UniDB->hasExceededSizeLimit()) { + storeBigObject(Index++); + } + PrevStoreSize = UniDB->getStorageSize(); + ASSERT_THAT_ERROR(UniDB->close(), Succeeded()); + EXPECT_TRUE(UniDB->needsGarbageCollection()); + + reopenDB(); + EXPECT_TRUE(UniDB->needsGarbageCollection()); + + std::optional<size_t> DirSizeBefore; + ASSERT_THAT_ERROR(countFileSizes(Temp.path()).moveInto(DirSizeBefore), + Succeeded()); + + ASSERT_THAT_ERROR(UnifiedOnDiskCache::collectGarbage(Temp.path()), + Succeeded()); + + std::optional<size_t> DirSizeAfter; + ASSERT_THAT_ERROR(countFileSizes(Temp.path()).moveInto(DirSizeAfter), + Succeeded()); + EXPECT_LT(*DirSizeAfter, *DirSizeBefore); + + reopenDB(); + EXPECT_FALSE(UniDB->needsGarbageCollection()); + + checkRootTree(); + checkKey(Key1Hash, "root"); + + EXPECT_LT(UniDB->getStorageSize(), PrevStoreSize); + + // 'Other' tree and 'Key2' got garbage-collected. + { + OnDiskGraphDB &DB = UniDB->getGraphDB(); + std::optional<ObjectID> ID; + ASSERT_THAT_ERROR(DB.getReference(OtherHash).moveInto(ID), Succeeded()); + EXPECT_FALSE(DB.containsObject(*ID)); + std::optional<ObjectID> Val; + ASSERT_THAT_ERROR(cacheGet(UniDB->getKeyValueDB(), Key2Hash).moveInto(Val), + Succeeded()); + EXPECT_FALSE(Val.has_value()); + } +} diff --git a/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp b/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp index 5c96199..fab40b9 100644 --- a/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp +++ b/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp @@ -84,7 +84,7 @@ public: class RandomAccessVisitorTest : public testing::Test { public: - RandomAccessVisitorTest() {} + RandomAccessVisitorTest() = default; static void SetUpTestCase() { GlobalState = std::make_unique<GlobalTestState>(); diff --git a/llvm/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp b/llvm/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp index b1f19e9..62b7591 100644 --- a/llvm/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp +++ b/llvm/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp @@ -21,7 +21,7 @@ using namespace llvm::codeview; class TypeIndexIteratorTest : public testing::Test { public: - TypeIndexIteratorTest() {} + TypeIndexIteratorTest() = default; void SetUp() override { Refs.clear(); diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp index 2fe5260..aa5b292 100644 --- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp @@ -864,7 +864,7 @@ TEST_F(DebugLineBasicFixture, CallbackUsedForUnterminatedSequence) { } struct AdjustAddressFixtureBase : public CommonFixture { - virtual ~AdjustAddressFixtureBase() {} + virtual ~AdjustAddressFixtureBase() = default; // Create and update the prologue as specified by the subclass, then return // the length of the table. diff --git a/llvm/unittests/ExecutionEngine/JITLink/JITLinkTestUtils.h b/llvm/unittests/ExecutionEngine/JITLink/JITLinkTestUtils.h index f03c82f..a2732e3 100644 --- a/llvm/unittests/ExecutionEngine/JITLink/JITLinkTestUtils.h +++ b/llvm/unittests/ExecutionEngine/JITLink/JITLinkTestUtils.h @@ -19,7 +19,7 @@ class MockJITLinkMemoryManager : public llvm::jitlink::JITLinkMemoryManager { public: class Alloc { public: - virtual ~Alloc() {} + virtual ~Alloc() = default; }; class SimpleAlloc : public Alloc { diff --git a/llvm/unittests/IR/ConstantsTest.cpp b/llvm/unittests/IR/ConstantsTest.cpp index 6376165..9cb9e12 100644 --- a/llvm/unittests/IR/ConstantsTest.cpp +++ b/llvm/unittests/IR/ConstantsTest.cpp @@ -29,13 +29,8 @@ TEST(ConstantsTest, UseCounts) { EXPECT_TRUE(Zero->use_empty()); EXPECT_EQ(Zero->getNumUses(), 0u); - EXPECT_TRUE(Zero->hasNUses(0)); EXPECT_FALSE(Zero->hasOneUse()); EXPECT_FALSE(Zero->hasOneUser()); - EXPECT_FALSE(Zero->hasNUses(1)); - EXPECT_FALSE(Zero->hasNUsesOrMore(1)); - EXPECT_FALSE(Zero->hasNUses(2)); - EXPECT_FALSE(Zero->hasNUsesOrMore(2)); std::unique_ptr<Module> M(new Module("MyModule", Context)); @@ -50,15 +45,36 @@ TEST(ConstantsTest, UseCounts) { // Still looks like use_empty with uses. EXPECT_TRUE(Zero->use_empty()); EXPECT_EQ(Zero->getNumUses(), 0u); - EXPECT_TRUE(Zero->hasNUses(0)); EXPECT_FALSE(Zero->hasOneUse()); EXPECT_FALSE(Zero->hasOneUser()); - EXPECT_FALSE(Zero->hasNUses(1)); - EXPECT_FALSE(Zero->hasNUsesOrMore(1)); - EXPECT_FALSE(Zero->hasNUses(2)); - EXPECT_FALSE(Zero->hasNUsesOrMore(2)); } +#ifdef GTEST_HAS_DEATH_TEST +#ifndef NDEBUG + +TEST(ConstantsTest, hasNUsesInvalid) { + LLVMContext Context; + Type *Int32Ty = Type::getInt32Ty(Context); + Constant *Zero = ConstantInt::get(Int32Ty, 0); + std::unique_ptr<Module> M(new Module("MyModule", Context)); + + // Introduce some uses + new GlobalVariable(*M, Int32Ty, /*isConstant=*/false, + GlobalValue::ExternalLinkage, /*Initializer=*/Zero, + "gv_user0"); + new GlobalVariable(*M, Int32Ty, /*isConstant=*/false, + GlobalValue::ExternalLinkage, /*Initializer=*/Zero, + "gv_user1"); + + for (int I = 0; I != 3; ++I) { + EXPECT_DEATH(Zero->hasNUses(I), "hasUseList\\(\\)"); + EXPECT_DEATH(Zero->hasNUsesOrMore(I), "hasUseList\\(\\)"); + } +} + +#endif +#endif + TEST(ConstantsTest, Integer_i1) { LLVMContext Context; IntegerType *Int1 = IntegerType::get(Context, 1); diff --git a/llvm/unittests/MC/SystemZ/SystemZMCDisassemblerTest.cpp b/llvm/unittests/MC/SystemZ/SystemZMCDisassemblerTest.cpp index 87fad37..25c22d1 100644 --- a/llvm/unittests/MC/SystemZ/SystemZMCDisassemblerTest.cpp +++ b/llvm/unittests/MC/SystemZ/SystemZMCDisassemblerTest.cpp @@ -61,7 +61,7 @@ Context &getContext() { class SystemZMCSymbolizerTest : public MCSymbolizer { public: SystemZMCSymbolizerTest(MCContext &MC) : MCSymbolizer(MC, nullptr) {} - ~SystemZMCSymbolizerTest() override {} + ~SystemZMCSymbolizerTest() override = default; bool tryAddingSymbolicOperand([[maybe_unused]] MCInst &Inst, [[maybe_unused]] raw_ostream &CStream, diff --git a/llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp b/llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp index 286528f..6d44151 100644 --- a/llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp +++ b/llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp @@ -62,7 +62,7 @@ Context &getContext() { class X86MCSymbolizerTest : public MCSymbolizer { public: X86MCSymbolizerTest(MCContext &MC) : MCSymbolizer(MC, nullptr) {} - ~X86MCSymbolizerTest() override {} + ~X86MCSymbolizerTest() override = default; struct OpInfo { int64_t Value = 0; diff --git a/llvm/unittests/MIR/MachineMetadata.cpp b/llvm/unittests/MIR/MachineMetadata.cpp index 0f038d9..5875512 100644 --- a/llvm/unittests/MIR/MachineMetadata.cpp +++ b/llvm/unittests/MIR/MachineMetadata.cpp @@ -33,7 +33,7 @@ using namespace llvm; class MachineMetadataTest : public testing::Test { public: - MachineMetadataTest() {} + MachineMetadataTest() = default; protected: LLVMContext Context; diff --git a/llvm/unittests/MIR/MachineStableHashTest.cpp b/llvm/unittests/MIR/MachineStableHashTest.cpp index ea0de1a..bedecb1 100644 --- a/llvm/unittests/MIR/MachineStableHashTest.cpp +++ b/llvm/unittests/MIR/MachineStableHashTest.cpp @@ -22,7 +22,7 @@ using namespace llvm; class MachineStableHashTest : public testing::Test { public: - MachineStableHashTest() {} + MachineStableHashTest() = default; protected: LLVMContext Context; diff --git a/llvm/unittests/Support/raw_ostream_proxy_test.cpp b/llvm/unittests/Support/raw_ostream_proxy_test.cpp index 864dda7..446e64a 100644 --- a/llvm/unittests/Support/raw_ostream_proxy_test.cpp +++ b/llvm/unittests/Support/raw_ostream_proxy_test.cpp @@ -40,8 +40,6 @@ public: bool IsDisplayed = false; }; -constexpr size_t BufferedNoPwriteSmallVectorStream::PreferredBufferSize; - TEST(raw_ostream_proxyTest, write) { // Besides confirming that "write" works, this test confirms that the proxy // takes on the buffer from the stream it's proxying, such that writes to the diff --git a/llvm/unittests/Target/AArch64/AArch64InstPrinterTest.cpp b/llvm/unittests/Target/AArch64/AArch64InstPrinterTest.cpp index 4dfc0bc..a835a34 100644 --- a/llvm/unittests/Target/AArch64/AArch64InstPrinterTest.cpp +++ b/llvm/unittests/Target/AArch64/AArch64InstPrinterTest.cpp @@ -36,10 +36,8 @@ static std::string AArch64InstPrinterTestPrintAlignedLabel(uint64_t value) { MCAsmInfo MAI; MCInstrInfo MII; MCRegisterInfo MRI; - MCSubtargetInfo STI(Triple(""), "", "", "", {}, - ArrayRef((SubtargetFeatureKV *)NULL, (size_t)0), - ArrayRef((SubtargetSubTypeKV *)NULL, (size_t)0), NULL, - NULL, NULL, NULL, NULL, NULL); + MCSubtargetInfo STI(Triple(""), "", "", "", {}, {}, {}, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr); MCContext Ctx(Triple(""), &MAI, &MRI, &STI); MCInst MI; diff --git a/llvm/unittests/Transforms/Utils/LocalTest.cpp b/llvm/unittests/Transforms/Utils/LocalTest.cpp index 4b53cc3..4908eda 100644 --- a/llvm/unittests/Transforms/Utils/LocalTest.cpp +++ b/llvm/unittests/Transforms/Utils/LocalTest.cpp @@ -1153,7 +1153,7 @@ TEST(Local, ExpressionForConstant) { IntegerType *Int1Ty = Type::getInt1Ty(Context); Expr = createExpression(ConstantInt::getTrue(Context), Int1Ty); EXPECT_NE(Expr, nullptr); - EXPECT_EQ(Expr->getElement(1), 18446744073709551615U); + EXPECT_EQ(Expr->getElement(1), 1U); Expr = createExpression(ConstantInt::getFalse(Context), Int1Ty); EXPECT_NE(Expr, nullptr); diff --git a/llvm/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp index 7a66117b..5bc489b 100644 --- a/llvm/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp @@ -28,7 +28,7 @@ using testing::IsEmpty; using testing::Not; using testing::NotNull; -constexpr const char kTriple[] = "aarch64-unknown-linux"; +constexpr char kTriple[] = "aarch64-unknown-linux"; class AArch64TargetTest : public ::testing::Test { protected: diff --git a/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp index 39c4260..0e90654 100644 --- a/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp @@ -26,7 +26,7 @@ using testing::NotNull; using testing::IsEmpty; using testing::Not; -constexpr const char kTriple[] = "powerpc64le-unknown-linux"; +constexpr char kTriple[] = "powerpc64le-unknown-linux"; class PowerPCTargetTest : public PPCTestBase { protected: diff --git a/llvm/unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp index c6f3448..7a40901de 100644 --- a/llvm/unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp @@ -49,8 +49,8 @@ protected: Fill(Sink); } - static constexpr const unsigned kMinInstructions = 3; - static constexpr const unsigned kLoopBodySize = 5; + static constexpr unsigned kMinInstructions = 3; + static constexpr unsigned kLoopBodySize = 5; std::unique_ptr<TargetMachine> TM; std::unique_ptr<LLVMContext> Context; diff --git a/llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp index a0cad28..08c18e4 100644 --- a/llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp @@ -29,7 +29,7 @@ namespace exegesis { // This needs to be updated anytime a test is added or removed from the test // suite. -static constexpr const size_t TestCount = 4; +static constexpr size_t TestCount = 4; class SubprocessMemoryTest : public X86TestBase { protected: diff --git a/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp index 9ebdb12..5a21a69 100644 --- a/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp @@ -582,7 +582,7 @@ TEST_F(X86Core2TargetTest, SetRegToDf0) { TEST_F(X86Core2Avx512TargetTest, FillMemoryOperands_ADD64rm) { const Instruction &I = getInstr(X86::ADD64rm); InstructionTemplate IT(&I); - constexpr const int kOffset = 42; + constexpr int kOffset = 42; State.getExegesisTarget().fillMemoryOperands(IT, X86::RDI, kOffset); // Memory is operands 2-6. EXPECT_THAT(IT.getValueFor(I.Operands[2]), IsReg(X86::RDI)); @@ -595,7 +595,7 @@ TEST_F(X86Core2Avx512TargetTest, FillMemoryOperands_ADD64rm) { TEST_F(X86Core2Avx512TargetTest, FillMemoryOperands_VGATHERDPSZ128rm) { const Instruction &I = getInstr(X86::VGATHERDPSZ128rm); InstructionTemplate IT(&I); - constexpr const int kOffset = 42; + constexpr int kOffset = 42; State.getExegesisTarget().fillMemoryOperands(IT, X86::RDI, kOffset); // Memory is operands 4-8. EXPECT_THAT(IT.getValueFor(I.Operands[4]), IsReg(X86::RDI)); @@ -625,9 +625,9 @@ TEST_F(X86Core2TargetTest, GenerateLowerMunmapTest) { } #ifdef __arm__ -static constexpr const uintptr_t VAddressSpaceCeiling = 0xC0000000; +static constexpr uintptr_t VAddressSpaceCeiling = 0xC0000000; #else -static constexpr const uintptr_t VAddressSpaceCeiling = 0x0000800000000000; +static constexpr uintptr_t VAddressSpaceCeiling = 0x0000800000000000; #endif TEST_F(X86Core2TargetTest, GenerateUpperMunmapTest) { diff --git a/llvm/unittests/tools/llvm-exegesis/X86/TestBase.h b/llvm/unittests/tools/llvm-exegesis/X86/TestBase.h index 4122726..b4c84d1 100644 --- a/llvm/unittests/tools/llvm-exegesis/X86/TestBase.h +++ b/llvm/unittests/tools/llvm-exegesis/X86/TestBase.h @@ -22,7 +22,7 @@ namespace exegesis { void InitializeX86ExegesisTarget(); -constexpr const char kTriple[] = "x86_64-unknown-linux"; +constexpr char kTriple[] = "x86_64-unknown-linux"; class X86TestBase : public ::testing::Test { protected: |
