From 0068f19cfdf2d01f101744776d3b5a3e500cf619 Mon Sep 17 00:00:00 2001 From: Mandeep Singh Grang Date: Sat, 7 Apr 2018 01:29:45 +0000 Subject: [PATCH] [unittests] Change std::sort to llvm::sort in response to r327219 r327219 added wrappers to std::sort which randomly shuffle the container before sorting. This will help in uncovering non-determinism caused due to undefined sorting order of objects having the same key. To make use of that infrastructure we need to invoke llvm::sort instead of std::sort. Note: This patch is one of a series of patches to replace *all* std::sort to llvm::sort. Refer the comments section in D44363 for a list of all the required patches. llvm-svn: 329475 --- unittests/ADT/STLExtrasTest.cpp | 4 ++-- unittests/ADT/SmallPtrSetTest.cpp | 2 +- unittests/ADT/StringMapTest.cpp | 4 ++-- unittests/Analysis/LazyCallGraphTest.cpp | 22 +++++++++---------- unittests/ProfileData/InstrProfTest.cpp | 10 ++++----- unittests/Support/Path.cpp | 12 +++++----- .../googlemock/include/gmock/gmock-matchers.h | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/unittests/ADT/STLExtrasTest.cpp b/unittests/ADT/STLExtrasTest.cpp index 89e876eb4de..d744a3cd521 100644 --- a/unittests/ADT/STLExtrasTest.cpp +++ b/unittests/ADT/STLExtrasTest.cpp @@ -302,8 +302,8 @@ TEST(STLExtrasTest, PartitionAdaptor) { ASSERT_EQ(V.begin() + 4, I); // Sort the two halves as partition may have messed with the order. - std::sort(V.begin(), I); - std::sort(I, V.end()); + llvm::sort(V.begin(), I); + llvm::sort(I, V.end()); EXPECT_EQ(2, V[0]); EXPECT_EQ(4, V[1]); diff --git a/unittests/ADT/SmallPtrSetTest.cpp b/unittests/ADT/SmallPtrSetTest.cpp index 0070d1cbae1..a428767aa31 100644 --- a/unittests/ADT/SmallPtrSetTest.cpp +++ b/unittests/ADT/SmallPtrSetTest.cpp @@ -299,7 +299,7 @@ TEST(SmallPtrSetTest, dereferenceAndIterate) { // Sort. We should hit the first element just once and the final element N // times. - std::sort(std::begin(Found), std::end(Found)); + llvm::sort(std::begin(Found), std::end(Found)); for (auto F = std::begin(Found), E = std::end(Found); F != E; ++F) EXPECT_EQ(F - Found + 1, *F); } diff --git a/unittests/ADT/StringMapTest.cpp b/unittests/ADT/StringMapTest.cpp index 6e0ea0e48ff..1f5c4f03164 100644 --- a/unittests/ADT/StringMapTest.cpp +++ b/unittests/ADT/StringMapTest.cpp @@ -279,7 +279,7 @@ TEST_F(StringMapTest, IterMapKeys) { Map["D"] = 3; auto Keys = to_vector<4>(Map.keys()); - std::sort(Keys.begin(), Keys.end()); + llvm::sort(Keys.begin(), Keys.end()); SmallVector Expected = {"A", "B", "C", "D"}; EXPECT_EQ(Expected, Keys); @@ -293,7 +293,7 @@ TEST_F(StringMapTest, IterSetKeys) { Set.insert("D"); auto Keys = to_vector<4>(Set.keys()); - std::sort(Keys.begin(), Keys.end()); + llvm::sort(Keys.begin(), Keys.end()); SmallVector Expected = {"A", "B", "C", "D"}; EXPECT_EQ(Expected, Keys); diff --git a/unittests/Analysis/LazyCallGraphTest.cpp b/unittests/Analysis/LazyCallGraphTest.cpp index cb8eb375605..6279ebb9b5a 100644 --- a/unittests/Analysis/LazyCallGraphTest.cpp +++ b/unittests/Analysis/LazyCallGraphTest.cpp @@ -264,7 +264,7 @@ TEST(LazyCallGraphTest, BasicGraphFormation) { for (LazyCallGraph::Edge &E : A1.populate()) Nodes.push_back(E.getFunction().getName()); - std::sort(Nodes.begin(), Nodes.end()); + llvm::sort(Nodes.begin(), Nodes.end()); EXPECT_EQ("a2", Nodes[0]); EXPECT_EQ("b2", Nodes[1]); EXPECT_EQ("c3", Nodes[2]); @@ -279,7 +279,7 @@ TEST(LazyCallGraphTest, BasicGraphFormation) { for (LazyCallGraph::Edge &E : B1.populate()) Nodes.push_back(E.getFunction().getName()); - std::sort(Nodes.begin(), Nodes.end()); + llvm::sort(Nodes.begin(), Nodes.end()); EXPECT_EQ("b2", Nodes[0]); EXPECT_EQ("d3", Nodes[1]); Nodes.clear(); @@ -293,7 +293,7 @@ TEST(LazyCallGraphTest, BasicGraphFormation) { for (LazyCallGraph::Edge &E : C1.populate()) Nodes.push_back(E.getFunction().getName()); - std::sort(Nodes.begin(), Nodes.end()); + llvm::sort(Nodes.begin(), Nodes.end()); EXPECT_EQ("c2", Nodes[0]); EXPECT_EQ("d2", Nodes[1]); Nodes.clear(); @@ -323,7 +323,7 @@ TEST(LazyCallGraphTest, BasicGraphFormation) { ASSERT_EQ(1, D.size()); for (LazyCallGraph::Node &N : *D.begin()) Nodes.push_back(N.getFunction().getName()); - std::sort(Nodes.begin(), Nodes.end()); + llvm::sort(Nodes.begin(), Nodes.end()); EXPECT_EQ(3u, Nodes.size()); EXPECT_EQ("d1", Nodes[0]); EXPECT_EQ("d2", Nodes[1]); @@ -339,7 +339,7 @@ TEST(LazyCallGraphTest, BasicGraphFormation) { ASSERT_EQ(1, C.size()); for (LazyCallGraph::Node &N : *C.begin()) Nodes.push_back(N.getFunction().getName()); - std::sort(Nodes.begin(), Nodes.end()); + llvm::sort(Nodes.begin(), Nodes.end()); EXPECT_EQ(3u, Nodes.size()); EXPECT_EQ("c1", Nodes[0]); EXPECT_EQ("c2", Nodes[1]); @@ -355,7 +355,7 @@ TEST(LazyCallGraphTest, BasicGraphFormation) { ASSERT_EQ(1, B.size()); for (LazyCallGraph::Node &N : *B.begin()) Nodes.push_back(N.getFunction().getName()); - std::sort(Nodes.begin(), Nodes.end()); + llvm::sort(Nodes.begin(), Nodes.end()); EXPECT_EQ(3u, Nodes.size()); EXPECT_EQ("b1", Nodes[0]); EXPECT_EQ("b2", Nodes[1]); @@ -373,7 +373,7 @@ TEST(LazyCallGraphTest, BasicGraphFormation) { ASSERT_EQ(1, A.size()); for (LazyCallGraph::Node &N : *A.begin()) Nodes.push_back(N.getFunction().getName()); - std::sort(Nodes.begin(), Nodes.end()); + llvm::sort(Nodes.begin(), Nodes.end()); EXPECT_EQ(3u, Nodes.size()); EXPECT_EQ("a1", Nodes[0]); EXPECT_EQ("a2", Nodes[1]); @@ -477,7 +477,7 @@ TEST(LazyCallGraphTest, InnerSCCFormation) { LazyCallGraph::SCC &D = *J++; for (LazyCallGraph::Node &N : D) Nodes.push_back(N.getFunction().getName()); - std::sort(Nodes.begin(), Nodes.end()); + llvm::sort(Nodes.begin(), Nodes.end()); EXPECT_EQ(3u, Nodes.size()); EXPECT_EQ("d1", Nodes[0]); EXPECT_EQ("d2", Nodes[1]); @@ -487,7 +487,7 @@ TEST(LazyCallGraphTest, InnerSCCFormation) { LazyCallGraph::SCC &B = *J++; for (LazyCallGraph::Node &N : B) Nodes.push_back(N.getFunction().getName()); - std::sort(Nodes.begin(), Nodes.end()); + llvm::sort(Nodes.begin(), Nodes.end()); EXPECT_EQ(3u, Nodes.size()); EXPECT_EQ("b1", Nodes[0]); EXPECT_EQ("b2", Nodes[1]); @@ -497,7 +497,7 @@ TEST(LazyCallGraphTest, InnerSCCFormation) { LazyCallGraph::SCC &C = *J++; for (LazyCallGraph::Node &N : C) Nodes.push_back(N.getFunction().getName()); - std::sort(Nodes.begin(), Nodes.end()); + llvm::sort(Nodes.begin(), Nodes.end()); EXPECT_EQ(3u, Nodes.size()); EXPECT_EQ("c1", Nodes[0]); EXPECT_EQ("c2", Nodes[1]); @@ -507,7 +507,7 @@ TEST(LazyCallGraphTest, InnerSCCFormation) { LazyCallGraph::SCC &A = *J++; for (LazyCallGraph::Node &N : A) Nodes.push_back(N.getFunction().getName()); - std::sort(Nodes.begin(), Nodes.end()); + llvm::sort(Nodes.begin(), Nodes.end()); EXPECT_EQ(3u, Nodes.size()); EXPECT_EQ("a1", Nodes[0]); EXPECT_EQ("a2", Nodes[1]); diff --git a/unittests/ProfileData/InstrProfTest.cpp b/unittests/ProfileData/InstrProfTest.cpp index 09be2e3dad7..0c99f7fde65 100644 --- a/unittests/ProfileData/InstrProfTest.cpp +++ b/unittests/ProfileData/InstrProfTest.cpp @@ -712,7 +712,7 @@ TEST_P(MaybeSparseInstrProfTest, value_prof_data_read_write) { }; std::unique_ptr VD_0( Record.getValueForSite(IPVK_IndirectCallTarget, 0)); - std::sort(&VD_0[0], &VD_0[5], Cmp); + llvm::sort(&VD_0[0], &VD_0[5], Cmp); ASSERT_EQ(StringRef((const char *)VD_0[0].Value, 7), StringRef("callee2")); ASSERT_EQ(1000U, VD_0[0].Count); ASSERT_EQ(StringRef((const char *)VD_0[1].Value, 7), StringRef("callee3")); @@ -726,7 +726,7 @@ TEST_P(MaybeSparseInstrProfTest, value_prof_data_read_write) { std::unique_ptr VD_1( Record.getValueForSite(IPVK_IndirectCallTarget, 1)); - std::sort(&VD_1[0], &VD_1[4], Cmp); + llvm::sort(&VD_1[0], &VD_1[4], Cmp); ASSERT_EQ(StringRef((const char *)VD_1[0].Value, 7), StringRef("callee2")); ASSERT_EQ(2500U, VD_1[0].Count); ASSERT_EQ(StringRef((const char *)VD_1[1].Value, 7), StringRef("callee1")); @@ -738,7 +738,7 @@ TEST_P(MaybeSparseInstrProfTest, value_prof_data_read_write) { std::unique_ptr VD_2( Record.getValueForSite(IPVK_IndirectCallTarget, 2)); - std::sort(&VD_2[0], &VD_2[3], Cmp); + llvm::sort(&VD_2[0], &VD_2[3], Cmp); ASSERT_EQ(StringRef((const char *)VD_2[0].Value, 7), StringRef("callee4")); ASSERT_EQ(5500U, VD_2[0].Count); ASSERT_EQ(StringRef((const char *)VD_2[1].Value, 7), StringRef("callee3")); @@ -748,7 +748,7 @@ TEST_P(MaybeSparseInstrProfTest, value_prof_data_read_write) { std::unique_ptr VD_3( Record.getValueForSite(IPVK_IndirectCallTarget, 3)); - std::sort(&VD_3[0], &VD_3[2], Cmp); + llvm::sort(&VD_3[0], &VD_3[2], Cmp); ASSERT_EQ(StringRef((const char *)VD_3[0].Value, 7), StringRef("callee3")); ASSERT_EQ(2000U, VD_3[0].Count); ASSERT_EQ(StringRef((const char *)VD_3[1].Value, 7), StringRef("callee2")); @@ -781,7 +781,7 @@ TEST_P(MaybeSparseInstrProfTest, value_prof_data_read_write_mapping) { }; std::unique_ptr VD_0( Record.getValueForSite(IPVK_IndirectCallTarget, 0)); - std::sort(&VD_0[0], &VD_0[5], Cmp); + llvm::sort(&VD_0[0], &VD_0[5], Cmp); ASSERT_EQ(VD_0[0].Value, 0x2000ULL); ASSERT_EQ(1000U, VD_0[0].Count); ASSERT_EQ(VD_0[1].Value, 0x3000ULL); diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index 8b053b33ec2..d1592692088 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -900,8 +900,8 @@ TEST_F(FileSystemTest, BrokenSymlinkDirectoryIteration) { ASSERT_NO_ERROR(ec); VisitedNonBrokenSymlinks.push_back(path::filename(i->path())); } - std::sort(VisitedNonBrokenSymlinks.begin(), VisitedNonBrokenSymlinks.end()); - std::sort(VisitedBrokenSymlinks.begin(), VisitedBrokenSymlinks.end()); + llvm::sort(VisitedNonBrokenSymlinks.begin(), VisitedNonBrokenSymlinks.end()); + llvm::sort(VisitedBrokenSymlinks.begin(), VisitedBrokenSymlinks.end()); v_t ExpectedNonBrokenSymlinks = {"b", "d"}; ASSERT_EQ(ExpectedNonBrokenSymlinks.size(), VisitedNonBrokenSymlinks.size()); ASSERT_TRUE(std::equal(VisitedNonBrokenSymlinks.begin(), @@ -927,8 +927,8 @@ TEST_F(FileSystemTest, BrokenSymlinkDirectoryIteration) { ASSERT_NO_ERROR(ec); VisitedNonBrokenSymlinks.push_back(path::filename(i->path())); } - std::sort(VisitedNonBrokenSymlinks.begin(), VisitedNonBrokenSymlinks.end()); - std::sort(VisitedBrokenSymlinks.begin(), VisitedBrokenSymlinks.end()); + llvm::sort(VisitedNonBrokenSymlinks.begin(), VisitedNonBrokenSymlinks.end()); + llvm::sort(VisitedBrokenSymlinks.begin(), VisitedBrokenSymlinks.end()); ExpectedNonBrokenSymlinks = {"b", "bb", "d", "da", "dd", "ddd", "ddd"}; ASSERT_EQ(ExpectedNonBrokenSymlinks.size(), VisitedNonBrokenSymlinks.size()); ASSERT_TRUE(std::equal(VisitedNonBrokenSymlinks.begin(), @@ -954,8 +954,8 @@ TEST_F(FileSystemTest, BrokenSymlinkDirectoryIteration) { ASSERT_NO_ERROR(ec); VisitedNonBrokenSymlinks.push_back(path::filename(i->path())); } - std::sort(VisitedNonBrokenSymlinks.begin(), VisitedNonBrokenSymlinks.end()); - std::sort(VisitedBrokenSymlinks.begin(), VisitedBrokenSymlinks.end()); + llvm::sort(VisitedNonBrokenSymlinks.begin(), VisitedNonBrokenSymlinks.end()); + llvm::sort(VisitedBrokenSymlinks.begin(), VisitedBrokenSymlinks.end()); ExpectedNonBrokenSymlinks = {"a", "b", "ba", "bb", "bc", "c", "d", "da", "dd", "ddd", "e"}; ASSERT_EQ(ExpectedNonBrokenSymlinks.size(), VisitedNonBrokenSymlinks.size()); diff --git a/utils/unittest/googlemock/include/gmock/gmock-matchers.h b/utils/unittest/googlemock/include/gmock/gmock-matchers.h index 749a30e4e6d..9f001c9e63c 100644 --- a/utils/unittest/googlemock/include/gmock/gmock-matchers.h +++ b/utils/unittest/googlemock/include/gmock/gmock-matchers.h @@ -2654,7 +2654,7 @@ class WhenSortedByMatcher { LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); ::std::vector sorted_container(lhs_stl_container.begin(), lhs_stl_container.end()); - ::std::sort( + ::llvm::sort( sorted_container.begin(), sorted_container.end(), comparator_); if (!listener->IsInterested()) {