[llvm] r329475 - [unittests] Change std::sort to llvm::sort in response to r327219
Mandeep Singh Grang via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 6 18:29:45 PDT 2018
Author: mgrang
Date: Fri Apr 6 18:29:45 2018
New Revision: 329475
URL: http://llvm.org/viewvc/llvm-project?rev=329475&view=rev
Log:
[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.
Modified:
llvm/trunk/unittests/ADT/STLExtrasTest.cpp
llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp
llvm/trunk/unittests/ADT/StringMapTest.cpp
llvm/trunk/unittests/Analysis/LazyCallGraphTest.cpp
llvm/trunk/unittests/ProfileData/InstrProfTest.cpp
llvm/trunk/unittests/Support/Path.cpp
llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-matchers.h
Modified: llvm/trunk/unittests/ADT/STLExtrasTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/STLExtrasTest.cpp?rev=329475&r1=329474&r2=329475&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/STLExtrasTest.cpp (original)
+++ llvm/trunk/unittests/ADT/STLExtrasTest.cpp Fri Apr 6 18:29:45 2018
@@ -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]);
Modified: llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp?rev=329475&r1=329474&r2=329475&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp (original)
+++ llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp Fri Apr 6 18:29:45 2018
@@ -299,7 +299,7 @@ TEST(SmallPtrSetTest, dereferenceAndIter
// 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);
}
Modified: llvm/trunk/unittests/ADT/StringMapTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/StringMapTest.cpp?rev=329475&r1=329474&r2=329475&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/StringMapTest.cpp (original)
+++ llvm/trunk/unittests/ADT/StringMapTest.cpp Fri Apr 6 18:29:45 2018
@@ -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<StringRef, 4> 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<StringRef, 4> Expected = {"A", "B", "C", "D"};
EXPECT_EQ(Expected, Keys);
Modified: llvm/trunk/unittests/Analysis/LazyCallGraphTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/LazyCallGraphTest.cpp?rev=329475&r1=329474&r2=329475&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/LazyCallGraphTest.cpp (original)
+++ llvm/trunk/unittests/Analysis/LazyCallGraphTest.cpp Fri Apr 6 18:29:45 2018
@@ -264,7 +264,7 @@ TEST(LazyCallGraphTest, BasicGraphFormat
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, BasicGraphFormat
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, BasicGraphFormat
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, BasicGraphFormat
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, BasicGraphFormat
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, BasicGraphFormat
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, BasicGraphFormat
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, InnerSCCFormatio
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, InnerSCCFormatio
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, InnerSCCFormatio
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, InnerSCCFormatio
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]);
Modified: llvm/trunk/unittests/ProfileData/InstrProfTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=329475&r1=329474&r2=329475&view=diff
==============================================================================
--- llvm/trunk/unittests/ProfileData/InstrProfTest.cpp (original)
+++ llvm/trunk/unittests/ProfileData/InstrProfTest.cpp Fri Apr 6 18:29:45 2018
@@ -712,7 +712,7 @@ TEST_P(MaybeSparseInstrProfTest, value_p
};
std::unique_ptr<InstrProfValueData[]> 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_p
std::unique_ptr<InstrProfValueData[]> 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_p
std::unique_ptr<InstrProfValueData[]> 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_p
std::unique_ptr<InstrProfValueData[]> 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_p
};
std::unique_ptr<InstrProfValueData[]> 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);
Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=329475&r1=329474&r2=329475&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Fri Apr 6 18:29:45 2018
@@ -900,8 +900,8 @@ TEST_F(FileSystemTest, BrokenSymlinkDire
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, BrokenSymlinkDire
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, BrokenSymlinkDire
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());
Modified: llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-matchers.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-matchers.h?rev=329475&r1=329474&r2=329475&view=diff
==============================================================================
--- llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-matchers.h (original)
+++ llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-matchers.h Fri Apr 6 18:29:45 2018
@@ -2654,7 +2654,7 @@ class WhenSortedByMatcher {
LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(),
lhs_stl_container.end());
- ::std::sort(
+ ::llvm::sort(
sorted_container.begin(), sorted_container.end(), comparator_);
if (!listener->IsInterested()) {
More information about the llvm-commits
mailing list