src: introduce upx::max and friends; updates for clang-19 git snapshot

This commit is contained in:
Markus F.X.J. Oberhumer
2024-05-15 14:06:05 +02:00
parent 9e0f16a629
commit 40b7e24fcc
21 changed files with 254 additions and 159 deletions
+37
View File
@@ -230,6 +230,43 @@ struct CheckIntegral {
}
checkU<T>();
checkU<typename std::add_const<T>::type>();
{
T zero, one, three, four;
zero = 0;
one = 1;
three = 3;
four = 4;
// min / max
assert_noexcept(upx::min(one, four) == 1);
assert_noexcept(upx::min(one, four) == one);
assert_noexcept(upx::max(one, four) == 4);
assert_noexcept(upx::max(one, four) == four);
// align
assert_noexcept(upx::align_down(zero, four) == 0);
assert_noexcept(upx::align_down(zero, four) == zero);
assert_noexcept(upx::align_down(one, four) == 0);
assert_noexcept(upx::align_down(one, four) == zero);
assert_noexcept(upx::align_down(three, four) == 0);
assert_noexcept(upx::align_down(three, four) == zero);
assert_noexcept(upx::align_down(four, four) == 4);
assert_noexcept(upx::align_down(four, four) == four);
assert_noexcept(upx::align_up(zero, four) == 0);
assert_noexcept(upx::align_up(zero, four) == zero);
assert_noexcept(upx::align_up(one, four) == 4);
assert_noexcept(upx::align_up(one, four) == four);
assert_noexcept(upx::align_up(three, four) == 4);
assert_noexcept(upx::align_up(three, four) == four);
assert_noexcept(upx::align_up(four, four) == 4);
assert_noexcept(upx::align_up(four, four) == four);
assert_noexcept(upx::align_gap(zero, four) == 0);
assert_noexcept(upx::align_gap(zero, four) == zero);
assert_noexcept(upx::align_gap(one, four) == 3);
assert_noexcept(upx::align_gap(one, four) == three);
assert_noexcept(upx::align_gap(three, four) == 1);
assert_noexcept(upx::align_gap(three, four) == one);
assert_noexcept(upx::align_gap(four, four) == 0);
assert_noexcept(upx::align_gap(four, four) == zero);
}
}
};
+33 -3
View File
@@ -122,10 +122,10 @@ TEST_CASE("std::vector") {
CHECK(v.end() - v.begin() == N);
CHECK(&v[0] == &(*(v.begin())));
// CHECK(&v[0] + N == &(*(v.end()))); // TODO later: is this legal??
// TODO later: make sure that this throws
#if defined(_LIBCPP_HARDENING_MODE_DEBUG) && \
#if defined(_LIBCPP_HARDENING_MODE) && defined(_LIBCPP_HARDENING_MODE_DEBUG) && \
(_LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG)
CHECK_THROWS((void) &v[N]);
// unfortunately this does not throw but aborts
////CHECK_THROWS((void) &v[N]);
#endif
UNUSED(v);
}
@@ -251,6 +251,36 @@ struct Z2_X2 : public X2 {
// util
**************************************************************************/
TEST_CASE("upx::min_max") {
static_assert(upx::min(0, 0) == 0);
static_assert(upx::min(0, 1) == 0);
static_assert(upx::min(1, 0) == 0);
static_assert(upx::max(0, 0) == 0);
static_assert(upx::max(0, 1) == 1);
static_assert(upx::max(1, 0) == 1);
static_assert(upx::umin(0u, 0u) == 0u);
static_assert(upx::umin(0u, 1u) == 0u);
static_assert(upx::umin(1u, 0u) == 0u);
static_assert(upx::umax(0u, 0u) == 0u);
static_assert(upx::umax(0u, 1u) == 1u);
static_assert(upx::umax(1u, 0u) == 1u);
CHECK_EQ(upx::align_down(0, 4), 0);
CHECK_EQ(upx::align_down(1, 4), 0);
CHECK_EQ(upx::align_down(2, 4), 0);
CHECK_EQ(upx::align_down(3, 4), 0);
CHECK_EQ(upx::align_down(4, 4), 4);
CHECK_EQ(upx::align_up(0, 4), 0);
CHECK_EQ(upx::align_up(1, 4), 4);
CHECK_EQ(upx::align_up(2, 4), 4);
CHECK_EQ(upx::align_up(3, 4), 4);
CHECK_EQ(upx::align_up(4, 4), 4);
CHECK_EQ(upx::align_gap(0, 4), 0);
CHECK_EQ(upx::align_gap(1, 4), 3);
CHECK_EQ(upx::align_gap(2, 4), 2);
CHECK_EQ(upx::align_gap(3, 4), 1);
CHECK_EQ(upx::align_gap(4, 4), 0);
}
#if WITH_THREADS
TEST_CASE("upx::ptr_std_atomic_cast") {
// pointer-size