mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[upstream_utils] Upgrade to LLVM 19.1.6 (#7101)
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#endif
|
||||
|
||||
#include "wpi/DenseMap.h"
|
||||
#include "CountCopyAndMove.h"
|
||||
#include "wpi/DenseMapInfo.h"
|
||||
#include "wpi/DenseMapInfoVariant.h"
|
||||
#include "gmock/gmock.h"
|
||||
@@ -24,7 +25,6 @@
|
||||
using namespace wpi;
|
||||
|
||||
namespace {
|
||||
|
||||
uint32_t getTestKey(int i, uint32_t *) { return i; }
|
||||
uint32_t getTestValue(int i, uint32_t *) { return 42 + i; }
|
||||
|
||||
@@ -39,6 +39,14 @@ uint32_t *getTestValue(int i, uint32_t **) {
|
||||
return &dummy_arr1[i];
|
||||
}
|
||||
|
||||
enum class EnumClass { Val };
|
||||
|
||||
EnumClass getTestKey(int i, EnumClass *) {
|
||||
// We can't possibly support 100 values for the swap test, so just return an
|
||||
// invalid EnumClass for testing.
|
||||
return static_cast<EnumClass>(i);
|
||||
}
|
||||
|
||||
/// A test class that tries to check that construction and destruction
|
||||
/// occur correctly.
|
||||
class CtorTester {
|
||||
@@ -107,14 +115,19 @@ template <typename T>
|
||||
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>,
|
||||
SmallDenseMap<uint32_t, uint32_t>,
|
||||
SmallDenseMap<uint32_t *, uint32_t *>,
|
||||
SmallDenseMap<CtorTester, CtorTester, 4,
|
||||
CtorTesterMapInfo>
|
||||
CtorTesterMapInfo>,
|
||||
SmallDenseMap<EnumClass, uint32_t>
|
||||
> DenseMapTestTypes;
|
||||
// clang-format on
|
||||
|
||||
TYPED_TEST_SUITE(DenseMapTest, DenseMapTestTypes, );
|
||||
|
||||
// Empty map tests
|
||||
@@ -350,29 +363,6 @@ TYPED_TEST(DenseMapTest, ConstIteratorTest) {
|
||||
EXPECT_TRUE(cit == cit2);
|
||||
}
|
||||
|
||||
namespace {
|
||||
// Simple class that counts how many moves and copy happens when growing a map
|
||||
struct CountCopyAndMove {
|
||||
static int Move;
|
||||
static int Copy;
|
||||
CountCopyAndMove() {}
|
||||
|
||||
CountCopyAndMove(const CountCopyAndMove &) { Copy++; }
|
||||
CountCopyAndMove &operator=(const CountCopyAndMove &) {
|
||||
Copy++;
|
||||
return *this;
|
||||
}
|
||||
CountCopyAndMove(CountCopyAndMove &&) { Move++; }
|
||||
CountCopyAndMove &operator=(const CountCopyAndMove &&) {
|
||||
Move++;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
int CountCopyAndMove::Copy = 0;
|
||||
int CountCopyAndMove::Move = 0;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// Test initializer list construction.
|
||||
TEST(DenseMapCustomTest, InitializerList) {
|
||||
DenseMap<int, int> M({{0, 0}, {0, 1}, {1, 2}});
|
||||
@@ -405,8 +395,8 @@ TEST(DenseMapCustomTest, DefaultMinReservedSizeTest) {
|
||||
// Will allocate 64 buckets
|
||||
Map.reserve(1);
|
||||
unsigned MemorySize = Map.getMemorySize();
|
||||
CountCopyAndMove::Copy = 0;
|
||||
CountCopyAndMove::Move = 0;
|
||||
CountCopyAndMove::ResetCounts();
|
||||
|
||||
for (int i = 0; i < ExpectedMaxInitialEntries; ++i)
|
||||
Map.insert(std::pair<int, CountCopyAndMove>(std::piecewise_construct,
|
||||
std::forward_as_tuple(i),
|
||||
@@ -414,9 +404,9 @@ TEST(DenseMapCustomTest, DefaultMinReservedSizeTest) {
|
||||
// Check that we didn't grow
|
||||
EXPECT_EQ(MemorySize, Map.getMemorySize());
|
||||
// Check that move was called the expected number of times
|
||||
EXPECT_EQ(ExpectedMaxInitialEntries, CountCopyAndMove::Move);
|
||||
EXPECT_EQ(ExpectedMaxInitialEntries, CountCopyAndMove::TotalMoves());
|
||||
// Check that no copy occurred
|
||||
EXPECT_EQ(0, CountCopyAndMove::Copy);
|
||||
EXPECT_EQ(0, CountCopyAndMove::TotalCopies());
|
||||
|
||||
// Adding one extra element should grow the map
|
||||
Map.insert(std::pair<int, CountCopyAndMove>(
|
||||
@@ -429,7 +419,7 @@ TEST(DenseMapCustomTest, DefaultMinReservedSizeTest) {
|
||||
// This relies on move-construction elision, and cannot be reliably tested.
|
||||
// EXPECT_EQ(ExpectedMaxInitialEntries + 2, CountCopyAndMove::Move);
|
||||
// Check that no copy occurred
|
||||
EXPECT_EQ(0, CountCopyAndMove::Copy);
|
||||
EXPECT_EQ(0, CountCopyAndMove::TotalCopies());
|
||||
}
|
||||
|
||||
// Make sure creating the map with an initial size of N actually gives us enough
|
||||
@@ -443,8 +433,8 @@ TEST(DenseMapCustomTest, InitialSizeTest) {
|
||||
for (auto Size : {1, 2, 48, 66}) {
|
||||
DenseMap<int, CountCopyAndMove> Map(Size);
|
||||
unsigned MemorySize = Map.getMemorySize();
|
||||
CountCopyAndMove::Copy = 0;
|
||||
CountCopyAndMove::Move = 0;
|
||||
CountCopyAndMove::ResetCounts();
|
||||
|
||||
for (int i = 0; i < Size; ++i)
|
||||
Map.insert(std::pair<int, CountCopyAndMove>(std::piecewise_construct,
|
||||
std::forward_as_tuple(i),
|
||||
@@ -452,9 +442,9 @@ TEST(DenseMapCustomTest, InitialSizeTest) {
|
||||
// Check that we didn't grow
|
||||
EXPECT_EQ(MemorySize, Map.getMemorySize());
|
||||
// Check that move was called the expected number of times
|
||||
EXPECT_EQ(Size, CountCopyAndMove::Move);
|
||||
EXPECT_EQ(Size, CountCopyAndMove::TotalMoves());
|
||||
// Check that no copy occurred
|
||||
EXPECT_EQ(0, CountCopyAndMove::Copy);
|
||||
EXPECT_EQ(0, CountCopyAndMove::TotalCopies());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,15 +455,14 @@ TEST(DenseMapCustomTest, InitFromIterator) {
|
||||
const int Count = 65;
|
||||
Values.reserve(Count);
|
||||
for (int i = 0; i < Count; i++)
|
||||
Values.emplace_back(i, CountCopyAndMove());
|
||||
Values.emplace_back(i, CountCopyAndMove(i));
|
||||
|
||||
CountCopyAndMove::Move = 0;
|
||||
CountCopyAndMove::Copy = 0;
|
||||
CountCopyAndMove::ResetCounts();
|
||||
DenseMap<int, CountCopyAndMove> Map(Values.begin(), Values.end());
|
||||
// Check that no move occurred
|
||||
EXPECT_EQ(0, CountCopyAndMove::Move);
|
||||
EXPECT_EQ(0, CountCopyAndMove::TotalMoves());
|
||||
// Check that copy was called the expected number of times
|
||||
EXPECT_EQ(Count, CountCopyAndMove::Copy);
|
||||
EXPECT_EQ(Count, CountCopyAndMove::TotalCopies());
|
||||
}
|
||||
|
||||
// Make sure reserve actually gives us enough buckets to insert N items
|
||||
@@ -488,8 +477,7 @@ TEST(DenseMapCustomTest, ReserveTest) {
|
||||
DenseMap<int, CountCopyAndMove> Map;
|
||||
Map.reserve(Size);
|
||||
unsigned MemorySize = Map.getMemorySize();
|
||||
CountCopyAndMove::Copy = 0;
|
||||
CountCopyAndMove::Move = 0;
|
||||
CountCopyAndMove::ResetCounts();
|
||||
for (int i = 0; i < Size; ++i)
|
||||
Map.insert(std::pair<int, CountCopyAndMove>(std::piecewise_construct,
|
||||
std::forward_as_tuple(i),
|
||||
@@ -497,12 +485,48 @@ TEST(DenseMapCustomTest, ReserveTest) {
|
||||
// Check that we didn't grow
|
||||
EXPECT_EQ(MemorySize, Map.getMemorySize());
|
||||
// Check that move was called the expected number of times
|
||||
EXPECT_EQ(Size, CountCopyAndMove::Move);
|
||||
EXPECT_EQ(Size, CountCopyAndMove::TotalMoves());
|
||||
// Check that no copy occurred
|
||||
EXPECT_EQ(0, CountCopyAndMove::Copy);
|
||||
EXPECT_EQ(0, CountCopyAndMove::TotalCopies());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DenseMapCustomTest, InsertOrAssignTest) {
|
||||
DenseMap<int, CountCopyAndMove> Map;
|
||||
|
||||
CountCopyAndMove val1(1);
|
||||
CountCopyAndMove::ResetCounts();
|
||||
auto try0 = Map.insert_or_assign(0, val1);
|
||||
EXPECT_TRUE(try0.second);
|
||||
EXPECT_EQ(0, CountCopyAndMove::TotalMoves());
|
||||
EXPECT_EQ(1, CountCopyAndMove::CopyConstructions);
|
||||
EXPECT_EQ(0, CountCopyAndMove::CopyAssignments);
|
||||
|
||||
CountCopyAndMove::ResetCounts();
|
||||
auto try1 = Map.insert_or_assign(0, val1);
|
||||
EXPECT_FALSE(try1.second);
|
||||
EXPECT_EQ(0, CountCopyAndMove::TotalMoves());
|
||||
EXPECT_EQ(0, CountCopyAndMove::CopyConstructions);
|
||||
EXPECT_EQ(1, CountCopyAndMove::CopyAssignments);
|
||||
|
||||
int key2 = 2;
|
||||
CountCopyAndMove val2(2);
|
||||
CountCopyAndMove::ResetCounts();
|
||||
auto try2 = Map.insert_or_assign(key2, std::move(val2));
|
||||
EXPECT_TRUE(try2.second);
|
||||
EXPECT_EQ(0, CountCopyAndMove::TotalCopies());
|
||||
EXPECT_EQ(1, CountCopyAndMove::MoveConstructions);
|
||||
EXPECT_EQ(0, CountCopyAndMove::MoveAssignments);
|
||||
|
||||
CountCopyAndMove val3(3);
|
||||
CountCopyAndMove::ResetCounts();
|
||||
auto try3 = Map.insert_or_assign(key2, std::move(val3));
|
||||
EXPECT_FALSE(try3.second);
|
||||
EXPECT_EQ(0, CountCopyAndMove::TotalCopies());
|
||||
EXPECT_EQ(0, CountCopyAndMove::MoveConstructions);
|
||||
EXPECT_EQ(1, CountCopyAndMove::MoveAssignments);
|
||||
}
|
||||
|
||||
// Key traits that allows lookup with either an unsigned or char* key;
|
||||
// In the latter case, "a" == 0, "b" == 1 and so on.
|
||||
struct TestDenseMapInfo {
|
||||
|
||||
Reference in New Issue
Block a user