mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[wpiutil] Upgrade to LLVM 18.1.1 (#6405)
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "wpi/Chrono.h"
|
||||
#include "wpi/SmallVector.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace wpi;
|
||||
|
||||
@@ -22,12 +22,17 @@ TEST(Endian, Read) {
|
||||
unsigned char bigval[] = {0x00, 0x01, 0x02, 0x03, 0x04};
|
||||
unsigned char littleval[] = {0x00, 0x04, 0x03, 0x02, 0x01};
|
||||
int32_t BigAsHost = 0x00010203;
|
||||
EXPECT_EQ(BigAsHost, (endian::read<int32_t, big, unaligned>(bigval)));
|
||||
EXPECT_EQ(BigAsHost,
|
||||
(endian::read<int32_t, wpi::endianness::big, unaligned>(bigval)));
|
||||
int32_t LittleAsHost = 0x02030400;
|
||||
EXPECT_EQ(LittleAsHost,(endian::read<int32_t, little, unaligned>(littleval)));
|
||||
EXPECT_EQ(
|
||||
LittleAsHost,
|
||||
(endian::read<int32_t, wpi::endianness::little, unaligned>(littleval)));
|
||||
|
||||
EXPECT_EQ((endian::read<int32_t, big, unaligned>(bigval + 1)),
|
||||
(endian::read<int32_t, little, unaligned>(littleval + 1)));
|
||||
EXPECT_EQ(
|
||||
(endian::read<int32_t, wpi::endianness::big, unaligned>(bigval + 1)),
|
||||
(endian::read<int32_t, wpi::endianness::little, unaligned>(littleval +
|
||||
1)));
|
||||
}
|
||||
|
||||
TEST(Endian, ReadBitAligned) {
|
||||
@@ -35,35 +40,43 @@ TEST(Endian, ReadBitAligned) {
|
||||
unsigned char littleval[] = {0x3f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff};
|
||||
unsigned char bigval[] = {0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xc0};
|
||||
EXPECT_EQ(
|
||||
(endian::readAtBitAlignment<int, little, unaligned>(&littleval[0], 6)),
|
||||
(endian::readAtBitAlignment<int, wpi::endianness::little, unaligned>(
|
||||
&littleval[0], 6)),
|
||||
0x0);
|
||||
EXPECT_EQ((endian::readAtBitAlignment<int, big, unaligned>(&bigval[0], 6)),
|
||||
EXPECT_EQ((endian::readAtBitAlignment<int, wpi::endianness::big, unaligned>(
|
||||
&bigval[0], 6)),
|
||||
0x0);
|
||||
// Test to make sure that signed right shift of 0xf0000000 is masked
|
||||
// properly.
|
||||
unsigned char littleval2[] = {0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00};
|
||||
unsigned char bigval2[] = {0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
EXPECT_EQ(
|
||||
(endian::readAtBitAlignment<int, little, unaligned>(&littleval2[0], 4)),
|
||||
(endian::readAtBitAlignment<int, wpi::endianness::little, unaligned>(
|
||||
&littleval2[0], 4)),
|
||||
0x0f000000);
|
||||
EXPECT_EQ((endian::readAtBitAlignment<int, big, unaligned>(&bigval2[0], 4)),
|
||||
EXPECT_EQ((endian::readAtBitAlignment<int, wpi::endianness::big, unaligned>(
|
||||
&bigval2[0], 4)),
|
||||
0x0f000000);
|
||||
// Test to make sure left shift of start bit doesn't overflow.
|
||||
EXPECT_EQ(
|
||||
(endian::readAtBitAlignment<int, little, unaligned>(&littleval2[0], 1)),
|
||||
(endian::readAtBitAlignment<int, wpi::endianness::little, unaligned>(
|
||||
&littleval2[0], 1)),
|
||||
0x78000000);
|
||||
EXPECT_EQ((endian::readAtBitAlignment<int, big, unaligned>(&bigval2[0], 1)),
|
||||
EXPECT_EQ((endian::readAtBitAlignment<int, wpi::endianness::big, unaligned>(
|
||||
&bigval2[0], 1)),
|
||||
0x78000000);
|
||||
// Test to make sure 64-bit int doesn't overflow.
|
||||
unsigned char littleval3[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
unsigned char bigval3[] = {0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
EXPECT_EQ((endian::readAtBitAlignment<int64_t, little, unaligned>(
|
||||
&littleval3[0], 4)),
|
||||
0x0f00000000000000);
|
||||
EXPECT_EQ(
|
||||
(endian::readAtBitAlignment<int64_t, big, unaligned>(&bigval3[0], 4)),
|
||||
(endian::readAtBitAlignment<int64_t, wpi::endianness::little, unaligned>(
|
||||
&littleval3[0], 4)),
|
||||
0x0f00000000000000);
|
||||
EXPECT_EQ(
|
||||
(endian::readAtBitAlignment<int64_t, wpi::endianness::big, unaligned>(
|
||||
&bigval3[0], 4)),
|
||||
0x0f00000000000000);
|
||||
}
|
||||
|
||||
@@ -71,8 +84,8 @@ TEST(Endian, WriteBitAligned) {
|
||||
// This test ensures that signed right shift of 0xffffaa is masked
|
||||
// properly.
|
||||
unsigned char bigval[8] = {0x00};
|
||||
endian::writeAtBitAlignment<int32_t, big, unaligned>(bigval, (int)0xffffaaaa,
|
||||
4);
|
||||
endian::writeAtBitAlignment<int32_t, wpi::endianness::big, unaligned>(
|
||||
bigval, (int)0xffffaaaa, 4);
|
||||
EXPECT_EQ(bigval[0], 0xff);
|
||||
EXPECT_EQ(bigval[1], 0xfa);
|
||||
EXPECT_EQ(bigval[2], 0xaa);
|
||||
@@ -83,8 +96,8 @@ TEST(Endian, WriteBitAligned) {
|
||||
EXPECT_EQ(bigval[7], 0x0f);
|
||||
|
||||
unsigned char littleval[8] = {0x00};
|
||||
endian::writeAtBitAlignment<int32_t, little, unaligned>(littleval,
|
||||
(int)0xffffaaaa, 4);
|
||||
endian::writeAtBitAlignment<int32_t, wpi::endianness::little, unaligned>(
|
||||
littleval, (int)0xffffaaaa, 4);
|
||||
EXPECT_EQ(littleval[0], 0xa0);
|
||||
EXPECT_EQ(littleval[1], 0xaa);
|
||||
EXPECT_EQ(littleval[2], 0xfa);
|
||||
@@ -97,8 +110,8 @@ TEST(Endian, WriteBitAligned) {
|
||||
// This test makes sure 1<<31 doesn't overflow.
|
||||
// Test to make sure left shift of start bit doesn't overflow.
|
||||
unsigned char bigval2[8] = {0x00};
|
||||
endian::writeAtBitAlignment<int32_t, big, unaligned>(bigval2, (int)0xffffffff,
|
||||
1);
|
||||
endian::writeAtBitAlignment<int32_t, wpi::endianness::big, unaligned>(
|
||||
bigval2, (int)0xffffffff, 1);
|
||||
EXPECT_EQ(bigval2[0], 0xff);
|
||||
EXPECT_EQ(bigval2[1], 0xff);
|
||||
EXPECT_EQ(bigval2[2], 0xff);
|
||||
@@ -109,8 +122,8 @@ TEST(Endian, WriteBitAligned) {
|
||||
EXPECT_EQ(bigval2[7], 0x01);
|
||||
|
||||
unsigned char littleval2[8] = {0x00};
|
||||
endian::writeAtBitAlignment<int32_t, little, unaligned>(littleval2,
|
||||
(int)0xffffffff, 1);
|
||||
endian::writeAtBitAlignment<int32_t, wpi::endianness::little, unaligned>(
|
||||
littleval2, (int)0xffffffff, 1);
|
||||
EXPECT_EQ(littleval2[0], 0xfe);
|
||||
EXPECT_EQ(littleval2[1], 0xff);
|
||||
EXPECT_EQ(littleval2[2], 0xff);
|
||||
@@ -122,7 +135,7 @@ TEST(Endian, WriteBitAligned) {
|
||||
|
||||
// Test to make sure 64-bit int doesn't overflow.
|
||||
unsigned char bigval64[16] = {0x00};
|
||||
endian::writeAtBitAlignment<int64_t, big, unaligned>(
|
||||
endian::writeAtBitAlignment<int64_t, wpi::endianness::big, unaligned>(
|
||||
bigval64, (int64_t)0xffffffffffffffff, 1);
|
||||
EXPECT_EQ(bigval64[0], 0xff);
|
||||
EXPECT_EQ(bigval64[1], 0xff);
|
||||
@@ -142,7 +155,7 @@ TEST(Endian, WriteBitAligned) {
|
||||
EXPECT_EQ(bigval64[15], 0x01);
|
||||
|
||||
unsigned char littleval64[16] = {0x00};
|
||||
endian::writeAtBitAlignment<int64_t, little, unaligned>(
|
||||
endian::writeAtBitAlignment<int64_t, wpi::endianness::little, unaligned>(
|
||||
littleval64, (int64_t)0xffffffffffffffff, 1);
|
||||
EXPECT_EQ(littleval64[0], 0xfe);
|
||||
EXPECT_EQ(littleval64[1], 0xff);
|
||||
@@ -164,23 +177,26 @@ TEST(Endian, WriteBitAligned) {
|
||||
|
||||
TEST(Endian, Write) {
|
||||
unsigned char data[5];
|
||||
endian::write<int32_t, big, unaligned>(data, -1362446643);
|
||||
endian::write<int32_t, wpi::endianness::big, unaligned>(data, -1362446643);
|
||||
EXPECT_EQ(data[0], 0xAE);
|
||||
EXPECT_EQ(data[1], 0xCA);
|
||||
EXPECT_EQ(data[2], 0xB6);
|
||||
EXPECT_EQ(data[3], 0xCD);
|
||||
endian::write<int32_t, big, unaligned>(data + 1, -1362446643);
|
||||
endian::write<int32_t, wpi::endianness::big, unaligned>(data + 1,
|
||||
-1362446643);
|
||||
EXPECT_EQ(data[1], 0xAE);
|
||||
EXPECT_EQ(data[2], 0xCA);
|
||||
EXPECT_EQ(data[3], 0xB6);
|
||||
EXPECT_EQ(data[4], 0xCD);
|
||||
|
||||
endian::write<int32_t, little, unaligned>(data, -1362446643);
|
||||
endian::write<int32_t, wpi::endianness::little, unaligned>(data,
|
||||
-1362446643);
|
||||
EXPECT_EQ(data[0], 0xCD);
|
||||
EXPECT_EQ(data[1], 0xB6);
|
||||
EXPECT_EQ(data[2], 0xCA);
|
||||
EXPECT_EQ(data[3], 0xAE);
|
||||
endian::write<int32_t, little, unaligned>(data + 1, -1362446643);
|
||||
endian::write<int32_t, wpi::endianness::little, unaligned>(data + 1,
|
||||
-1362446643);
|
||||
EXPECT_EQ(data[1], 0xCD);
|
||||
EXPECT_EQ(data[2], 0xB6);
|
||||
EXPECT_EQ(data[3], 0xCA);
|
||||
|
||||
@@ -16,10 +16,38 @@
|
||||
#include "wpi/MapVector.h"
|
||||
#include "wpi/iterator_range.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
using namespace wpi;
|
||||
|
||||
namespace {
|
||||
struct CountCopyAndMove {
|
||||
CountCopyAndMove() = default;
|
||||
CountCopyAndMove(const CountCopyAndMove &) { copy = 1; }
|
||||
CountCopyAndMove(CountCopyAndMove &&) { move = 1; }
|
||||
void operator=(const CountCopyAndMove &) { ++copy; }
|
||||
void operator=(CountCopyAndMove &&) { ++move; }
|
||||
int copy = 0;
|
||||
int move = 0;
|
||||
};
|
||||
|
||||
struct A : CountCopyAndMove {
|
||||
A(int v) : v(v) {}
|
||||
int v;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace wpi {
|
||||
template <> struct DenseMapInfo<A> {
|
||||
static inline A getEmptyKey() { return 0x7fffffff; }
|
||||
static inline A getTombstoneKey() { return -0x7fffffff - 1; }
|
||||
static unsigned getHashValue(const A &Val) { return (unsigned)(Val.v * 37U); }
|
||||
static bool isEqual(const A &LHS, const A &RHS) { return LHS.v == RHS.v; }
|
||||
};
|
||||
} // namespace wpi
|
||||
|
||||
namespace {
|
||||
TEST(MapVectorTest, swap) {
|
||||
MapVector<int, int> MV1, MV2;
|
||||
std::pair<MapVector<int, int>::iterator, bool> R;
|
||||
@@ -86,6 +114,87 @@ TEST(MapVectorTest, insert_pop) {
|
||||
EXPECT_EQ(MV[4], 7);
|
||||
}
|
||||
|
||||
TEST(MapVectorTest, try_emplace) {
|
||||
struct AAndU {
|
||||
A a;
|
||||
std::unique_ptr<int> b;
|
||||
AAndU(A a, std::unique_ptr<int> b) : a(a), b(std::move(b)) {}
|
||||
};
|
||||
MapVector<A, AAndU> mv;
|
||||
|
||||
A zero(0);
|
||||
auto try0 = mv.try_emplace(zero, zero, nullptr);
|
||||
EXPECT_TRUE(try0.second);
|
||||
EXPECT_EQ(0, try0.first->second.a.v);
|
||||
EXPECT_EQ(1, try0.first->second.a.copy);
|
||||
EXPECT_EQ(0, try0.first->second.a.move);
|
||||
|
||||
auto try1 = mv.try_emplace(zero, zero, nullptr);
|
||||
EXPECT_FALSE(try1.second);
|
||||
EXPECT_EQ(0, try1.first->second.a.v);
|
||||
EXPECT_EQ(1, try1.first->second.a.copy);
|
||||
EXPECT_EQ(0, try1.first->second.a.move);
|
||||
|
||||
EXPECT_EQ(try0.first, try1.first);
|
||||
EXPECT_EQ(1, try1.first->first.copy);
|
||||
EXPECT_EQ(0, try1.first->first.move);
|
||||
|
||||
A two(2);
|
||||
auto try2 = mv.try_emplace(2, std::move(two), std::make_unique<int>(2));
|
||||
EXPECT_TRUE(try2.second);
|
||||
EXPECT_EQ(2, try2.first->second.a.v);
|
||||
EXPECT_EQ(0, try2.first->second.a.move);
|
||||
|
||||
std::unique_ptr<int> p(new int(3));
|
||||
auto try3 = mv.try_emplace(std::move(two), 3, std::move(p));
|
||||
EXPECT_FALSE(try3.second);
|
||||
EXPECT_EQ(2, try3.first->second.a.v);
|
||||
EXPECT_EQ(1, try3.first->second.a.copy);
|
||||
EXPECT_EQ(0, try3.first->second.a.move);
|
||||
|
||||
EXPECT_EQ(try2.first, try3.first);
|
||||
EXPECT_EQ(0, try3.first->first.copy);
|
||||
EXPECT_EQ(1, try3.first->first.move);
|
||||
EXPECT_NE(nullptr, p);
|
||||
}
|
||||
|
||||
TEST(MapVectorTest, insert_or_assign) {
|
||||
MapVector<A, A> mv;
|
||||
|
||||
A zero(0);
|
||||
auto try0 = mv.insert_or_assign(zero, zero);
|
||||
EXPECT_TRUE(try0.second);
|
||||
EXPECT_EQ(0, try0.first->second.v);
|
||||
EXPECT_EQ(1, try0.first->second.copy);
|
||||
EXPECT_EQ(0, try0.first->second.move);
|
||||
|
||||
auto try1 = mv.insert_or_assign(zero, zero);
|
||||
EXPECT_FALSE(try1.second);
|
||||
EXPECT_EQ(0, try1.first->second.v);
|
||||
EXPECT_EQ(2, try1.first->second.copy);
|
||||
EXPECT_EQ(0, try1.first->second.move);
|
||||
|
||||
EXPECT_EQ(try0.first, try1.first);
|
||||
EXPECT_EQ(1, try1.first->first.copy);
|
||||
EXPECT_EQ(0, try1.first->first.move);
|
||||
|
||||
A two(2);
|
||||
auto try2 = mv.try_emplace(2, std::move(two));
|
||||
EXPECT_TRUE(try2.second);
|
||||
EXPECT_EQ(2, try2.first->second.v);
|
||||
EXPECT_EQ(1, try2.first->second.move);
|
||||
|
||||
auto try3 = mv.insert_or_assign(std::move(two), 3);
|
||||
EXPECT_FALSE(try3.second);
|
||||
EXPECT_EQ(3, try3.first->second.v);
|
||||
EXPECT_EQ(0, try3.first->second.copy);
|
||||
EXPECT_EQ(2, try3.first->second.move);
|
||||
|
||||
EXPECT_EQ(try2.first, try3.first);
|
||||
EXPECT_EQ(0, try3.first->first.copy);
|
||||
EXPECT_EQ(1, try3.first->first.move);
|
||||
}
|
||||
|
||||
TEST(MapVectorTest, erase) {
|
||||
MapVector<int, int> MV;
|
||||
|
||||
@@ -430,3 +539,4 @@ TEST(SmallMapVectorLargeTest, iteration_test) {
|
||||
count--;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -119,4 +119,21 @@ TEST(TransformTest, MoveTransformLlvm) {
|
||||
EXPECT_EQ(0u, MoveOnly::Destructions);
|
||||
}
|
||||
|
||||
TEST(TransformTest, ToUnderlying) {
|
||||
enum E { A1 = 0, B1 = -1 };
|
||||
static_assert(wpi::to_underlying(A1) == 0);
|
||||
static_assert(wpi::to_underlying(B1) == -1);
|
||||
|
||||
enum E2 : unsigned char { A2 = 0, B2 };
|
||||
static_assert(
|
||||
std::is_same_v<unsigned char, decltype(wpi::to_underlying(A2))>);
|
||||
static_assert(wpi::to_underlying(A2) == 0);
|
||||
static_assert(wpi::to_underlying(B2) == 1);
|
||||
|
||||
enum class E3 { A3 = -1, B3 };
|
||||
static_assert(std::is_same_v<int, decltype(wpi::to_underlying(E3::A3))>);
|
||||
static_assert(wpi::to_underlying(E3::A3) == -1);
|
||||
static_assert(wpi::to_underlying(E3::B3) == 0);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user