1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

src: fix compilation on older compilers; update tests

This commit is contained in:
Markus F.X.J. Oberhumer 2024-05-27 20:59:12 +02:00
parent 9f4d18baac
commit b0ce072370
4 changed files with 628 additions and 294 deletions

View File

@ -814,6 +814,32 @@ void upx_compiler_sanity_check(void) noexcept {
static_assert(get_be64_signed(e) == 9186918263483431288LL);
#endif
}
#if defined(upx_is_constant_evaluated)
{
constexpr upx_uint16_t v16 = 0x0201;
constexpr upx_uint32_t v32 = 0x04030201;
constexpr upx_uint64_t v64 = 0x0807060504030201ull;
constexpr BE16 be16 = BE16::make(v16);
constexpr BE32 be32 = BE32::make(v32);
constexpr BE64 be64 = BE64::make(v64);
constexpr LE16 le16 = LE16::make(v16);
constexpr LE32 le32 = LE32::make(v32);
constexpr LE64 le64 = LE64::make(v64);
using upx::compile_time::mem_eq;
static_assert(mem_eq(be16.d, "\x02\x01", 2));
static_assert(mem_eq(be32.d, "\x04\x03\x02\x01", 4));
static_assert(mem_eq(be64.d, "\x08\x07\x06\x05\x04\x03\x02\x01", 8));
static_assert(mem_eq(le16.d, "\x01\x02", 2));
static_assert(mem_eq(le32.d, "\x01\x02\x03\x04", 4));
static_assert(mem_eq(le64.d, "\x01\x02\x03\x04\x05\x06\x07\x08", 8));
constexpr NE16 ne16 = NE16::make(v16);
constexpr NE32 ne32 = NE32::make(v32);
constexpr NE64 ne64 = NE64::make(v64);
assert_noexcept(memcmp(&v16, ne16.d, 2) == 0);
assert_noexcept(memcmp(&v32, ne32.d, 4) == 0);
assert_noexcept(memcmp(&v64, ne64.d, 8) == 0);
}
#endif
#if DEBUG >= 1
{
for (int i = 0; i < 256; i++) {

View File

@ -32,108 +32,7 @@
#include "../conf.h"
/*************************************************************************
// compile-time checks
**************************************************************************/
static_assert(upx::is_same_all_v<int>);
static_assert(upx::is_same_all_v<int, int>);
static_assert(upx::is_same_all_v<int, int, int>);
static_assert(!upx::is_same_all_v<int, char>);
static_assert(!upx::is_same_all_v<int, char, int>);
static_assert(!upx::is_same_all_v<int, int, char>);
static_assert(!upx::is_same_any_v<int>);
static_assert(upx::is_same_any_v<int, int>);
static_assert(upx::is_same_any_v<int, char, int>);
static_assert(upx::is_same_any_v<int, int, char>);
static_assert(!upx::is_same_any_v<int, char>);
static_assert(!upx::is_same_any_v<int, char, char>);
static_assert(!upx::is_same_any_v<int, char, long>);
static_assert(upx::is_same_any_v<ptrdiff_t, int, long, long long>);
static_assert(upx::is_same_any_v<size_t, unsigned, unsigned long, unsigned long long>);
// TODO later: CHERI
static_assert(upx::is_same_any_v<upx_uintptr_t, unsigned, unsigned long, unsigned long long>);
static_assert(usizeof(int) == sizeof(int));
static_assert(usizeof('a') == sizeof(char));
static_assert(usizeof("") == 1);
static_assert(usizeof("a") == 2);
static_assert(usizeof("ab") == 3);
static_assert(usizeof(L'a') == sizeof(wchar_t));
static_assert(usizeof(L"") == 1 * sizeof(wchar_t));
static_assert(usizeof(L"a") == 2 * sizeof(wchar_t));
static_assert(usizeof(L"ab") == 3 * sizeof(wchar_t));
static_assert(usizeof(0) == sizeof(int));
static_assert(usizeof(0L) == sizeof(long));
static_assert(usizeof(0LL) == sizeof(long long));
static_assert(usizeof(nullptr) == sizeof(void *));
static_assert(usizeof(sizeof(0)) == sizeof(size_t));
static_assert(usizeof(usizeof(0)) == sizeof(unsigned));
#if 0
// works, but may trigger clang/gcc warnings "-Wunused-value"
static_assert(usizeof((1LL, 1)) == sizeof(int));
static_assert(usizeof((1, 1LL)) == sizeof(long long));
#endif
static_assert(upx::min<upx_int8_t>(1, 2) == 1);
static_assert(upx::min<upx_int16_t>(1, 2) == 1);
static_assert(upx::min(1, 2) == 1);
static_assert(upx::min(1ll, 2ll) == 1);
static_assert(upx::max<upx_int8_t>(1, 2) == 2);
static_assert(upx::max<upx_int16_t>(1, 2) == 2);
static_assert(upx::max(1, 2) == 2);
static_assert(upx::max(1ll, 2ll) == 2);
static_assert(upx::wrapping_add<upx_int8_t>(127, 2) == -127);
static_assert(upx::wrapping_add<upx_int16_t>(32767, 2) == -32767);
static_assert(upx::wrapping_add(2147483647, 2) == -2147483647);
static_assert(upx::wrapping_add(9223372036854775807ll, 2ll) == -9223372036854775807ll);
static_assert(upx::wrapping_sub<upx_int8_t>(-127, 2) == 127);
static_assert(upx::wrapping_sub<upx_int16_t>(-32767, 2) == 32767);
static_assert(upx::wrapping_sub(-2147483647, 2) == 2147483647);
static_assert(upx::wrapping_sub(-9223372036854775807ll, 2ll) == 9223372036854775807ll);
namespace compile_time = upx::compile_time;
static_assert(compile_time::string_len("") == 0);
static_assert(compile_time::string_len("a") == 1);
static_assert(compile_time::string_len("ab") == 2);
static_assert(compile_time::string_len("abc") == 3);
static_assert(compile_time::string_eq("", ""));
static_assert(!compile_time::string_eq("a", ""));
static_assert(!compile_time::string_eq("", "a"));
static_assert(compile_time::string_eq("abc", "abc"));
static_assert(!compile_time::string_eq("ab", "abc"));
static_assert(!compile_time::string_eq("abc", "ab"));
static_assert(!compile_time::string_lt("", ""));
static_assert(!compile_time::string_lt("a", ""));
static_assert(compile_time::string_lt("", "a"));
static_assert(!compile_time::string_lt("abc", "abc"));
static_assert(compile_time::string_lt("ab", "abc"));
static_assert(!compile_time::string_lt("abc", "ab"));
static_assert(!compile_time::string_lt("abc", "aba"));
static_assert(compile_time::string_lt("abc", "abz"));
static_assert(compile_time::string_ne("abc", "abz"));
static_assert(!compile_time::string_gt("abc", "abz"));
static_assert(!compile_time::string_ge("abc", "abz"));
static_assert(compile_time::string_le("abc", "abz"));
static_assert(compile_time::mem_eq((const char *) nullptr, (const char *) nullptr, 0));
static_assert(compile_time::mem_eq((const char *) nullptr, (const byte *) nullptr, 0));
static_assert(compile_time::mem_eq((const byte *) nullptr, (const char *) nullptr, 0));
static_assert(compile_time::mem_eq((const byte *) nullptr, (const byte *) nullptr, 0));
static_assert(compile_time::mem_eq("", "", 0));
static_assert(compile_time::mem_eq("abc", "abc", 3));
static_assert(!compile_time::mem_eq("abc", "abz", 3));
static_assert(compile_time::bswap16(0x0102) == 0x0201);
static_assert(compile_time::bswap32(0x01020304) == 0x04030201);
static_assert(compile_time::bswap64(0x0102030405060708ull) == 0x0807060504030201ull);
/*************************************************************************
//
// standard C++ library
**************************************************************************/
TEST_CASE("std::vector") {
@ -144,14 +43,14 @@ TEST_CASE("std::vector") {
// CHECK(&v[0] + N == &(*(v.end()))); // TODO later: is this legal??
#if defined(_LIBCPP_HARDENING_MODE) && defined(_LIBCPP_HARDENING_MODE_DEBUG) && \
(_LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG)
// unfortunately this does not throw but aborts
// unfortunately this does NOT throw but ABORTS
////CHECK_THROWS((void) &v[N]);
#endif
UNUSED(v);
}
/*************************************************************************
// UPX_CXX_DISABLE_xxx
// core util - UPX_CXX_DISABLE_xxx
**************************************************************************/
namespace {
@ -267,145 +166,106 @@ struct Z2_X2 : public X2 {
} // namespace test_disable_new_delete
/*************************************************************************
// <type_traits>
**************************************************************************/
static_assert(upx::is_same_all_v<int>);
static_assert(upx::is_same_all_v<int, int>);
static_assert(upx::is_same_all_v<int, int, int>);
static_assert(!upx::is_same_all_v<int, char>);
static_assert(!upx::is_same_all_v<int, char, int>);
static_assert(!upx::is_same_all_v<int, int, char>);
static_assert(!upx::is_same_any_v<int>);
static_assert(upx::is_same_any_v<int, int>);
static_assert(upx::is_same_any_v<int, char, int>);
static_assert(upx::is_same_any_v<int, int, char>);
static_assert(!upx::is_same_any_v<int, char>);
static_assert(!upx::is_same_any_v<int, char, char>);
static_assert(!upx::is_same_any_v<int, char, long>);
static_assert(upx::is_same_any_v<ptrdiff_t, int, long, long long>);
static_assert(upx::is_same_any_v<size_t, unsigned, unsigned long, unsigned long long>);
// TODO later: CHERI
static_assert(upx::is_same_any_v<upx_uintptr_t, unsigned, unsigned long, unsigned long long>);
/*************************************************************************
// <algorithm>
**************************************************************************/
static_assert(upx::align_down(0, 4) == 0);
static_assert(upx::align_down(1, 4) == 0);
static_assert(upx::align_down(2, 4) == 0);
static_assert(upx::align_down(3, 4) == 0);
static_assert(upx::align_down(4, 4) == 4);
static_assert(upx::align_up(0, 4) == 0);
static_assert(upx::align_up(1, 4) == 4);
static_assert(upx::align_up(2, 4) == 4);
static_assert(upx::align_up(3, 4) == 4);
static_assert(upx::align_up(4, 4) == 4);
static_assert(upx::align_gap(0, 4) == 0);
static_assert(upx::align_gap(1, 4) == 3);
static_assert(upx::align_gap(2, 4) == 2);
static_assert(upx::align_gap(3, 4) == 1);
static_assert(upx::align_gap(4, 4) == 0);
static_assert(upx::min<upx_int8_t>(1, 2) == 1);
static_assert(upx::min<upx_int16_t>(1, 2) == 1);
static_assert(upx::min(1, 2) == 1);
static_assert(upx::min(1ll, 2ll) == 1);
static_assert(upx::max<upx_int8_t>(1, 2) == 2);
static_assert(upx::max<upx_int16_t>(1, 2) == 2);
static_assert(upx::max(1, 2) == 2);
static_assert(upx::max(1ll, 2ll) == 2);
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);
static_assert(upx::wrapping_add<upx_int8_t>(127, 2) == -127);
static_assert(upx::wrapping_add<upx_int16_t>(32767, 2) == -32767);
static_assert(upx::wrapping_add(2147483647, 2) == -2147483647);
static_assert(upx::wrapping_add(9223372036854775807ll, 2ll) == -9223372036854775807ll);
static_assert(upx::wrapping_sub<upx_int8_t>(-127, 2) == 127);
static_assert(upx::wrapping_sub<upx_int16_t>(-32767, 2) == 32767);
static_assert(upx::wrapping_sub(-2147483647, 2) == 2147483647);
static_assert(upx::wrapping_sub(-9223372036854775807ll, 2ll) == 9223372036854775807ll);
/*************************************************************************
// 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
CHECK_EQ(upx::ptr_std_atomic_cast((void **) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((uintptr_t *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((upx_uintptr_t *) nullptr), nullptr);
#if 1
// more fundamental types
CHECK_EQ(upx::ptr_std_atomic_cast((char *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((short *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((int *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((long *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((ptrdiff_t *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((size_t *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((upx_int8_t *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((upx_int16_t *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((upx_int32_t *) nullptr), nullptr);
// upx::UnsignedSizeOf
static_assert(usizeof(int) == sizeof(int));
static_assert(usizeof('a') == sizeof(char));
static_assert(usizeof("") == 1);
static_assert(usizeof("a") == 2);
static_assert(usizeof("ab") == 3);
static_assert(usizeof(L'a') == sizeof(wchar_t));
static_assert(usizeof(L"") == 1 * sizeof(wchar_t));
static_assert(usizeof(L"a") == 2 * sizeof(wchar_t));
static_assert(usizeof(L"ab") == 3 * sizeof(wchar_t));
static_assert(usizeof(0) == sizeof(int));
static_assert(usizeof(0L) == sizeof(long));
static_assert(usizeof(0LL) == sizeof(long long));
static_assert(usizeof(nullptr) == sizeof(void *));
static_assert(usizeof(sizeof(0)) == sizeof(size_t));
static_assert(usizeof(usizeof(0)) == sizeof(unsigned));
#if 0
// works, but may trigger clang/gcc warnings "-Wunused-value"
static_assert(usizeof((1LL, 1)) == sizeof(int));
static_assert(usizeof((1, 1LL)) == sizeof(long long));
#endif
}
#endif
TEST_CASE("upx::atomic_exchange") {
{
upx_uintptr_t x = (upx_uintptr_t) 0 - 1;
upx_uintptr_t y = upx::atomic_exchange(&x, (upx_uintptr_t) 2);
CHECK_EQ(x, 2);
CHECK_EQ(y, (upx_uintptr_t) 0 - 1);
UNUSED(y);
}
{
const int buf[2] = {101, 202};
const int *ptr_array[2] = {&buf[0], &buf[1]};
assert_noexcept(*ptr_array[0] == 101 && *ptr_array[1] == 202);
const int *p = upx::atomic_exchange(&ptr_array[0], ptr_array[1]);
CHECK_EQ(p, buf + 0);
assert_noexcept(*ptr_array[0] == 202 && *ptr_array[1] == 202);
p = upx::atomic_exchange(&ptr_array[1], p);
CHECK_EQ(p, buf + 1);
assert_noexcept(*ptr_array[0] == 202 && *ptr_array[1] == 101);
UNUSED(p);
}
}
TEST_CASE("upx::ObjectDeleter 1") {
LE16 *o = nullptr; // object
LE32 *a = nullptr; // array
LE64 *m = nullptr; // malloc
{
auto o_deleter = upx::ObjectDeleter(&o, 1);
o = new LE16;
assert(o != nullptr);
auto a_deleter = upx::ArrayDeleter(&a, 1);
a = New(LE32, 1);
assert(a != nullptr);
auto m_deleter = upx::MallocDeleter(&m, 1);
m = (LE64 *) ::malloc(sizeof(LE64));
assert(m != nullptr);
}
assert(o == nullptr);
assert(a == nullptr);
assert(m == nullptr);
// test "const" versions
{
const auto o_deleter = upx::ObjectDeleter(&o, 1);
o = new LE16;
assert(o != nullptr);
const auto a_deleter = upx::ArrayDeleter(&a, 1);
a = New(LE32, 1);
assert(a != nullptr);
const auto m_deleter = upx::MallocDeleter(&m, 1);
m = (LE64 *) ::malloc(sizeof(LE64));
assert(m != nullptr);
}
assert(o == nullptr);
assert(a == nullptr);
assert(m == nullptr);
}
TEST_CASE("upx::ObjectDeleter 2") {
constexpr size_t N = 2;
BE16 *o[N]; // multiple objects
BE32 *a[N]; // multiple arrays
BE64 *m[N]; // multiple mallocs
{
auto o_deleter = upx::ObjectDeleter(o, 0);
auto a_deleter = upx::ArrayDeleter(a, 0);
auto m_deleter = upx::MallocDeleter(m, 0);
for (size_t i = 0; i < N; i++) {
o[i] = new BE16;
assert(o[i] != nullptr);
o_deleter.count += 1;
a[i] = New(BE32, 1 + i);
assert(a[i] != nullptr);
a_deleter.count += 1;
m[i] = (BE64 *) ::malloc(sizeof(BE64));
assert(m[i] != nullptr);
m_deleter.count += 1;
}
}
for (size_t i = 0; i < N; i++) {
assert(o[i] == nullptr);
assert(a[i] == nullptr);
assert(m[i] == nullptr);
}
}
TEST_CASE("upx::ptr_static_cast") {
// check that we do not trigger any -Wcast-align warnings
@ -552,6 +412,112 @@ TEST_CASE("upx::ptr_static_cast constexpr 2") {
//// constexpr unsigned *uc2 = ptr_static_cast<unsigned *>(ip);
}
#if WITH_THREADS
TEST_CASE("upx::ptr_std_atomic_cast") {
// pointer-size
CHECK_EQ(upx::ptr_std_atomic_cast((void **) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((uintptr_t *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((upx_uintptr_t *) nullptr), nullptr);
#if 1
// more fundamental types
CHECK_EQ(upx::ptr_std_atomic_cast((char *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((short *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((int *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((long *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((ptrdiff_t *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((size_t *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((upx_int8_t *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((upx_int16_t *) nullptr), nullptr);
CHECK_EQ(upx::ptr_std_atomic_cast((upx_int32_t *) nullptr), nullptr);
#endif
}
#endif // WITH_THREADS
TEST_CASE("upx::atomic_exchange") {
{
upx_uintptr_t x = (upx_uintptr_t) 0 - 1;
upx_uintptr_t y = upx::atomic_exchange(&x, (upx_uintptr_t) 2);
CHECK_EQ(x, 2);
CHECK_EQ(y, (upx_uintptr_t) 0 - 1);
UNUSED(y);
}
{
const int buf[2] = {101, 202};
const int *ptr_array[2] = {&buf[0], &buf[1]};
assert_noexcept(*ptr_array[0] == 101 && *ptr_array[1] == 202);
const int *p = upx::atomic_exchange(&ptr_array[0], ptr_array[1]);
CHECK_EQ(p, buf + 0);
assert_noexcept(*ptr_array[0] == 202 && *ptr_array[1] == 202);
p = upx::atomic_exchange(&ptr_array[1], p);
CHECK_EQ(p, buf + 1);
assert_noexcept(*ptr_array[0] == 202 && *ptr_array[1] == 101);
UNUSED(p);
}
}
TEST_CASE("upx::ObjectDeleter 1") {
LE16 *o = nullptr; // object
LE32 *a = nullptr; // array
LE64 *m = nullptr; // malloc
{
auto o_deleter = upx::ObjectDeleter(&o, 1);
o = new LE16;
assert(o != nullptr);
auto a_deleter = upx::ArrayDeleter(&a, 1);
a = New(LE32, 1);
assert(a != nullptr);
auto m_deleter = upx::MallocDeleter(&m, 1);
m = (LE64 *) ::malloc(sizeof(LE64));
assert(m != nullptr);
}
assert(o == nullptr);
assert(a == nullptr);
assert(m == nullptr);
// test "const" versions
{
const auto o_deleter = upx::ObjectDeleter(&o, 1);
o = new LE16;
assert(o != nullptr);
const auto a_deleter = upx::ArrayDeleter(&a, 1);
a = New(LE32, 1);
assert(a != nullptr);
const auto m_deleter = upx::MallocDeleter(&m, 1);
m = (LE64 *) ::malloc(sizeof(LE64));
assert(m != nullptr);
}
assert(o == nullptr);
assert(a == nullptr);
assert(m == nullptr);
}
TEST_CASE("upx::ObjectDeleter 2") {
constexpr size_t N = 2;
BE16 *o[N]; // multiple objects
BE32 *a[N]; // multiple arrays
BE64 *m[N]; // multiple mallocs
{
auto o_deleter = upx::ObjectDeleter(o, 0);
auto a_deleter = upx::ArrayDeleter(a, 0);
auto m_deleter = upx::MallocDeleter(m, 0);
for (size_t i = 0; i < N; i++) {
o[i] = new BE16;
assert(o[i] != nullptr);
o_deleter.count += 1;
a[i] = New(BE32, 1 + i);
assert(a[i] != nullptr);
a_deleter.count += 1;
m[i] = (BE64 *) ::malloc(sizeof(BE64));
assert(m[i] != nullptr);
m_deleter.count += 1;
}
}
for (size_t i = 0; i < N; i++) {
assert(o[i] == nullptr);
assert(a[i] == nullptr);
assert(m[i] == nullptr);
}
}
TEST_CASE("upx::noncopyable") {
struct Test : private upx::noncopyable {
int v = 1;
@ -570,12 +536,337 @@ TEST_CASE("upx::noncopyable") {
}
/*************************************************************************
// TriBool checks
// namespace upx::compile_time
**************************************************************************/
static_assert(upx::compile_time::string_len("") == 0);
static_assert(upx::compile_time::string_len("a") == 1);
static_assert(upx::compile_time::string_len("ab") == 2);
static_assert(upx::compile_time::string_len("abc") == 3);
static_assert(upx::compile_time::string_eq("", ""));
static_assert(!upx::compile_time::string_eq("a", ""));
static_assert(!upx::compile_time::string_eq("", "a"));
static_assert(upx::compile_time::string_eq("abc", "abc"));
static_assert(!upx::compile_time::string_eq("ab", "abc"));
static_assert(!upx::compile_time::string_eq("abc", "ab"));
static_assert(!upx::compile_time::string_lt("", ""));
static_assert(!upx::compile_time::string_lt("a", ""));
static_assert(upx::compile_time::string_lt("", "a"));
static_assert(!upx::compile_time::string_lt("abc", "abc"));
static_assert(upx::compile_time::string_lt("ab", "abc"));
static_assert(!upx::compile_time::string_lt("abc", "ab"));
static_assert(!upx::compile_time::string_lt("abc", "aba"));
static_assert(upx::compile_time::string_lt("abc", "abz"));
static_assert(upx::compile_time::string_ne("abc", "abz"));
static_assert(!upx::compile_time::string_gt("abc", "abz"));
static_assert(!upx::compile_time::string_ge("abc", "abz"));
static_assert(upx::compile_time::string_le("abc", "abz"));
static_assert(upx::compile_time::mem_eq((const char *) nullptr, (const char *) nullptr, 0));
static_assert(upx::compile_time::mem_eq((const char *) nullptr, (const byte *) nullptr, 0));
static_assert(upx::compile_time::mem_eq((const byte *) nullptr, (const char *) nullptr, 0));
static_assert(upx::compile_time::mem_eq((const byte *) nullptr, (const byte *) nullptr, 0));
static_assert(upx::compile_time::mem_eq("", "", 0));
static_assert(upx::compile_time::mem_eq("abc", "abc", 3));
static_assert(!upx::compile_time::mem_eq("abc", "abz", 3));
static_assert(upx::compile_time::bswap16(0x0102) == 0x0201);
static_assert(upx::compile_time::bswap32(0x01020304) == 0x04030201);
static_assert(upx::compile_time::bswap64(0x0102030405060708ull) == 0x0807060504030201ull);
namespace {
struct alignas(1) TestCT final {
byte d[8]; // public data
static constexpr TestCT makeBE16(upx_uint16_t v) noexcept {
TestCT x = {};
upx::compile_time::set_be16(x.d, v);
return x;
}
static constexpr TestCT makeBE24(upx_uint32_t v) noexcept {
TestCT x = {};
upx::compile_time::set_be24(x.d, v);
return x;
}
static constexpr TestCT makeBE32(upx_uint32_t v) noexcept {
TestCT x = {};
upx::compile_time::set_be32(x.d, v);
return x;
}
static constexpr TestCT makeBE64(upx_uint64_t v) noexcept {
TestCT x = {};
upx::compile_time::set_be64(x.d, v);
return x;
}
static constexpr TestCT makeLE16(upx_uint16_t v) noexcept {
TestCT x = {};
upx::compile_time::set_le16(x.d, v);
return x;
}
static constexpr TestCT makeLE24(upx_uint32_t v) noexcept {
TestCT x = {};
upx::compile_time::set_le24(x.d, v);
return x;
}
static constexpr TestCT makeLE32(upx_uint32_t v) noexcept {
TestCT x = {};
upx::compile_time::set_le32(x.d, v);
return x;
}
static constexpr TestCT makeLE64(upx_uint64_t v) noexcept {
TestCT x = {};
upx::compile_time::set_le64(x.d, v);
return x;
}
// run-time
static noinline upx_uint16_t noinline_bswap16(upx_uint16_t v) noexcept {
return upx::compile_time::bswap16(v);
}
static noinline upx_uint32_t noinline_bswap32(upx_uint32_t v) noexcept {
return upx::compile_time::bswap32(v);
}
static noinline upx_uint64_t noinline_bswap64(upx_uint64_t v) noexcept {
return upx::compile_time::bswap64(v);
}
static noinline upx_uint16_t noinline_get_be16(const byte *p) noexcept {
return upx::compile_time::get_be16(p);
}
static noinline upx_uint32_t noinline_get_be24(const byte *p) noexcept {
return upx::compile_time::get_be24(p);
}
static noinline upx_uint32_t noinline_get_be32(const byte *p) noexcept {
return upx::compile_time::get_be32(p);
}
static noinline upx_uint64_t noinline_get_be64(const byte *p) noexcept {
return upx::compile_time::get_be64(p);
}
static noinline upx_uint16_t noinline_get_le16(const byte *p) noexcept {
return upx::compile_time::get_le16(p);
}
static noinline upx_uint32_t noinline_get_le24(const byte *p) noexcept {
return upx::compile_time::get_le24(p);
}
static noinline upx_uint32_t noinline_get_le32(const byte *p) noexcept {
return upx::compile_time::get_le32(p);
}
static noinline upx_uint64_t noinline_get_le64(const byte *p) noexcept {
return upx::compile_time::get_le64(p);
}
static noinline void noinline_set_be16(byte * p, upx_uint16_t v) noexcept {
upx::compile_time::set_be16(p, v);
}
static noinline void noinline_set_be24(byte * p, upx_uint32_t v) noexcept {
upx::compile_time::set_be24(p, v);
}
static noinline void noinline_set_be32(byte * p, upx_uint32_t v) noexcept {
upx::compile_time::set_be32(p, v);
}
static noinline void noinline_set_be64(byte * p, upx_uint64_t v) noexcept {
upx::compile_time::set_be64(p, v);
}
static noinline void noinline_set_le16(byte * p, upx_uint16_t v) noexcept {
upx::compile_time::set_le16(p, v);
}
static noinline void noinline_set_le24(byte * p, upx_uint32_t v) noexcept {
upx::compile_time::set_le24(p, v);
}
static noinline void noinline_set_le32(byte * p, upx_uint32_t v) noexcept {
upx::compile_time::set_le32(p, v);
}
static noinline void noinline_set_le64(byte * p, upx_uint64_t v) noexcept {
upx::compile_time::set_le64(p, v);
}
};
static_assert(sizeof(TestCT) == 8);
static_assert(alignof(TestCT) == 1);
} // namespace
TEST_CASE("upx::compile_time") {
constexpr upx_uint16_t v16 = 0x0201;
constexpr upx_uint32_t v24 = 0x030201;
constexpr upx_uint32_t v32 = 0x04030201;
constexpr upx_uint64_t v64 = 0x0807060504030201ull;
{
static_assert(upx::compile_time::bswap16(v16) == 0x0102);
static_assert(upx::compile_time::bswap32(v32) == 0x01020304);
static_assert(upx::compile_time::bswap64(v64) == 0x0102030405060708ull);
assert_noexcept(TestCT::noinline_bswap16(v16) == 0x0102);
assert_noexcept(TestCT::noinline_bswap32(v32) == 0x01020304);
assert_noexcept(TestCT::noinline_bswap64(v64) == 0x0102030405060708ull);
}
{
constexpr const byte d[8] = {1, 2, 3, 4, 5, 6, 7, 8};
static_assert(upx::compile_time::get_be16(d) == 0x0102);
static_assert(upx::compile_time::get_be24(d) == 0x010203);
static_assert(upx::compile_time::get_be32(d) == 0x01020304);
static_assert(upx::compile_time::get_be64(d) == 0x0102030405060708ull);
static_assert(upx::compile_time::get_le16(d) == 0x0201);
static_assert(upx::compile_time::get_le24(d) == 0x030201);
static_assert(upx::compile_time::get_le32(d) == 0x04030201);
static_assert(upx::compile_time::get_le64(d) == 0x0807060504030201ull);
}
{
using upx::compile_time::mem_eq;
upx_alignas_max byte aligned_buffer[16] = {};
upx::compile_time::mem_set(aligned_buffer, 0xff, 16);
assert_noexcept(mem_eq(aligned_buffer, aligned_buffer + 8, 8));
byte *const buf = aligned_buffer + 7;
constexpr auto be16 = TestCT::makeBE16(v16);
static_assert(upx::compile_time::get_be16(be16.d) == v16);
static_assert(mem_eq(be16.d, "\x02\x01", 2));
upx::compile_time::mem_clear(buf, 8);
TestCT::noinline_set_be16(buf, v16);
assert_noexcept(TestCT::noinline_get_be16(buf) == v16);
assert_noexcept(upx::compile_time::get_be16(buf) == v16);
assert_noexcept(memcmp(buf, be16.d, 8) == 0);
constexpr auto be24 = TestCT::makeBE24(v24);
static_assert(upx::compile_time::get_be24(be24.d) == v24);
static_assert(mem_eq(be24.d, "\x03\x02\x01", 3));
upx::compile_time::mem_clear(buf, 8);
TestCT::noinline_set_be24(buf, v24);
assert_noexcept(TestCT::noinline_get_be24(buf) == v24);
assert_noexcept(upx::compile_time::get_be24(buf) == v24);
assert_noexcept(memcmp(buf, be24.d, 8) == 0);
constexpr auto be32 = TestCT::makeBE32(v32);
static_assert(upx::compile_time::get_be32(be32.d) == v32);
static_assert(mem_eq(be32.d, "\x04\x03\x02\x01", 4));
upx::compile_time::mem_clear(buf, 8);
TestCT::noinline_set_be32(buf, v32);
assert_noexcept(TestCT::noinline_get_be32(buf) == v32);
assert_noexcept(upx::compile_time::get_be32(buf) == v32);
assert_noexcept(memcmp(buf, be32.d, 8) == 0);
constexpr auto be64 = TestCT::makeBE64(v64);
static_assert(upx::compile_time::get_be64(be64.d) == v64);
static_assert(mem_eq(be64.d, "\x08\x07\x06\x05\x04\x03\x02\x01", 8));
upx::compile_time::mem_clear(buf, 8);
TestCT::noinline_set_be64(buf, v64);
assert_noexcept(TestCT::noinline_get_be64(buf) == v64);
assert_noexcept(upx::compile_time::get_be64(buf) == v64);
assert_noexcept(memcmp(buf, be64.d, 8) == 0);
constexpr auto le16 = TestCT::makeLE16(v16);
static_assert(upx::compile_time::get_le16(le16.d) == v16);
static_assert(mem_eq(le16.d, "\x01\x02", 2));
upx::compile_time::mem_clear(buf, 8);
TestCT::noinline_set_le16(buf, v16);
assert_noexcept(TestCT::noinline_get_le16(buf) == v16);
assert_noexcept(upx::compile_time::get_le16(buf) == v16);
assert_noexcept(memcmp(buf, le16.d, 8) == 0);
constexpr auto le24 = TestCT::makeLE24(v24);
static_assert(upx::compile_time::get_le24(le24.d) == v24);
static_assert(mem_eq(le24.d, "\x01\x02\x03", 3));
upx::compile_time::mem_clear(buf, 8);
TestCT::noinline_set_le24(buf, v24);
assert_noexcept(TestCT::noinline_get_le24(buf) == v24);
assert_noexcept(upx::compile_time::get_le24(buf) == v24);
assert_noexcept(memcmp(buf, le24.d, 8) == 0);
constexpr auto le32 = TestCT::makeLE32(v32);
static_assert(upx::compile_time::get_le32(le32.d) == v32);
static_assert(mem_eq(le32.d, "\x01\x02\x03\x04", 4));
upx::compile_time::mem_clear(buf, 8);
TestCT::noinline_set_le32(buf, v32);
assert_noexcept(TestCT::noinline_get_le32(buf) == v32);
assert_noexcept(upx::compile_time::get_le32(buf) == v32);
assert_noexcept(memcmp(buf, le32.d, 8) == 0);
constexpr auto le64 = TestCT::makeLE64(v64);
static_assert(upx::compile_time::get_le64(le64.d) == v64);
static_assert(mem_eq(le64.d, "\x01\x02\x03\x04\x05\x06\x07\x08", 8));
memset(buf, 0, 8);
TestCT::noinline_set_le64(buf, v64);
assert_noexcept(TestCT::noinline_get_le64(buf) == v64);
assert_noexcept(upx::compile_time::get_le64(buf) == v64);
assert_noexcept(memcmp(buf, le64.d, 8) == 0);
static_assert(upx::compile_time::bswap16(upx::compile_time::get_be16(be16.d)) ==
upx::compile_time::get_be16(le16.d));
static_assert(upx::compile_time::bswap32(upx::compile_time::get_be32(be32.d)) ==
upx::compile_time::get_be32(le32.d));
static_assert(upx::compile_time::bswap64(upx::compile_time::get_be64(be64.d)) ==
upx::compile_time::get_be64(le64.d));
assert_noexcept(TestCT::noinline_bswap16(TestCT::noinline_get_be16(be16.d)) ==
TestCT::noinline_get_be16(le16.d));
assert_noexcept(TestCT::noinline_bswap32(TestCT::noinline_get_be32(be32.d)) ==
TestCT::noinline_get_be32(le32.d));
assert_noexcept(TestCT::noinline_bswap64(TestCT::noinline_get_be64(be64.d)) ==
TestCT::noinline_get_be64(le64.d));
}
}
TEST_CASE("upx::compile_time") {
constexpr upx_uint16_t v16 = 0xf2f1;
constexpr upx_uint32_t v24 = 0xf3f2f1;
constexpr upx_uint32_t v32 = 0xf4f3f2f1;
constexpr upx_uint64_t v64 = 0xf8f7f6f5f4f3f2f1ull;
{
using upx::compile_time::mem_eq;
upx_alignas_max byte aligned_buffer[32];
byte *const buf1 = aligned_buffer + 3;
byte *const buf2 = aligned_buffer + 13;
upx::compile_time::set_be16(buf1, v16);
TestCT::noinline_set_be16(buf2, v16);
assert_noexcept(TestCT::noinline_get_be16(buf1) == v16);
assert_noexcept(TestCT::noinline_get_be16(buf2) == v16);
assert_noexcept(memcmp(buf1, buf2, 2) == 0);
upx::compile_time::set_be24(buf1, v24);
TestCT::noinline_set_be24(buf2, v24);
assert_noexcept(TestCT::noinline_get_be24(buf1) == v24);
assert_noexcept(TestCT::noinline_get_be24(buf2) == v24);
assert_noexcept(memcmp(buf1, buf2, 3) == 0);
upx::compile_time::set_be32(buf1, v32);
TestCT::noinline_set_be32(buf2, v32);
assert_noexcept(TestCT::noinline_get_be32(buf1) == v32);
assert_noexcept(TestCT::noinline_get_be32(buf2) == v32);
assert_noexcept(memcmp(buf1, buf2, 4) == 0);
upx::compile_time::set_be64(buf1, v64);
TestCT::noinline_set_be64(buf2, v64);
assert_noexcept(TestCT::noinline_get_be64(buf1) == v64);
assert_noexcept(TestCT::noinline_get_be64(buf2) == v64);
assert_noexcept(memcmp(buf1, buf2, 8) == 0);
upx::compile_time::set_le16(buf1, v16);
TestCT::noinline_set_le16(buf2, v16);
assert_noexcept(TestCT::noinline_get_le16(buf1) == v16);
assert_noexcept(TestCT::noinline_get_le16(buf2) == v16);
assert_noexcept(memcmp(buf1, buf2, 2) == 0);
upx::compile_time::set_le24(buf1, v24);
TestCT::noinline_set_le24(buf2, v24);
assert_noexcept(TestCT::noinline_get_le24(buf1) == v24);
assert_noexcept(TestCT::noinline_get_le24(buf2) == v24);
assert_noexcept(memcmp(buf1, buf2, 3) == 0);
upx::compile_time::set_le32(buf1, v32);
TestCT::noinline_set_le32(buf2, v32);
assert_noexcept(TestCT::noinline_get_le32(buf1) == v32);
assert_noexcept(TestCT::noinline_get_le32(buf2) == v32);
assert_noexcept(memcmp(buf1, buf2, 4) == 0);
upx::compile_time::set_le64(buf1, v64);
TestCT::noinline_set_le64(buf2, v64);
assert_noexcept(TestCT::noinline_get_le64(buf1) == v64);
assert_noexcept(TestCT::noinline_get_le64(buf2) == v64);
assert_noexcept(memcmp(buf1, buf2, 8) == 0);
}
}
/*************************************************************************
// TriBool
**************************************************************************/
namespace {
template <class T>
struct TestTriBool {
struct TestTriBool final {
static noinline void test(bool expect_true) {
static_assert(std::is_class<T>::value);
static_assert(std::is_nothrow_default_constructible<T>::value);

View File

@ -525,6 +525,9 @@ void show_sysinfo(const char *options_var) {
cf_print("__cplusplus", "%lld", __cplusplus + 0, 3);
#if defined(_MSVC_LANG)
cf_print("_MSVC_LANG", "%lld", _MSVC_LANG + 0, 3);
#endif
#if defined(upx_is_constant_evaluated)
cf_print("upx_is_constant_evaluated", "%lld", 1, 3);
#endif
// compiler
#if defined(ACC_CC_CLANG)
@ -591,9 +594,6 @@ void show_sysinfo(const char *options_var) {
cf_print("__GLIBC_MINOR__", "%lld", __GLIBC_MINOR__ + 0);
#endif
// misc compilation options
#if defined(upx_is_constant_evaluated)
cf_print("upx_is_constant_evaluated", "%lld", 1, 3);
#endif
#if defined(UPX_CONFIG_DISABLE_WSTRICT)
cf_print("UPX_CONFIG_DISABLE_WSTRICT", "%lld", UPX_CONFIG_DISABLE_WSTRICT + 0, 3);
#endif

View File

@ -395,102 +395,119 @@ constexpr bool mem_eq(const unsigned char *a, const char *b, std::size_t n) noex
return n == 0 || (*a == *b && mem_eq(a + 1, b + 1, n - 1));
}
constexpr void mem_set(char *p, char c, std::size_t n) noexcept {
(void) (n == 0 || (*p = c, mem_set(p + 1, c, n - 1), 0));
}
constexpr void mem_set(unsigned char *p, unsigned char c, std::size_t n) noexcept {
(void) (n == 0 || (*p = c, mem_set(p + 1, c, n - 1), 0));
}
forceinline constexpr void mem_clear(char *p, std::size_t n) noexcept { mem_set(p, (char) 0, n); }
forceinline constexpr void mem_clear(unsigned char *p, std::size_t n) noexcept {
mem_set(p, (unsigned char) 0, n);
}
forceinline constexpr upx_uint16_t bswap16(upx_uint16_t v) noexcept {
return ((v >> 8) & 0xff) | ((v & 0xff) << 8);
typedef unsigned U;
return (upx_uint16_t) ((((U) v >> 8) & 0xff) | (((U) v & 0xff) << 8));
}
forceinline constexpr upx_uint32_t bswap32(upx_uint32_t v) noexcept {
return ((v >> 24) & 0xff) | ((v >> 8) & 0xff00) | ((v & 0xff00) << 8) | ((v & 0xff) << 24);
typedef upx_uint32_t U;
return (upx_uint32_t) ((((U) v >> 24) & 0xff) | (((U) v >> 8) & 0xff00) |
(((U) v & 0xff00) << 8) | (((U) v & 0xff) << 24));
}
forceinline constexpr upx_uint64_t bswap64(upx_uint64_t v) noexcept {
return (upx_uint64_t(bswap32(upx_uint32_t(v))) << 32) | bswap32(upx_uint32_t(v >> 32));
return (upx_uint64_t) (((upx_uint64_t) bswap32((upx_uint32_t) v) << 32) |
bswap32((upx_uint32_t) (v >> 32)));
}
forceinline constexpr upx_uint16_t get_be16(const byte *p) noexcept {
typedef upx_uint16_t U;
return (U(p[0]) << 8) | (U(p[1]) << 0);
typedef unsigned U;
return (upx_uint16_t) (((U) p[0] << 8) | ((U) p[1] << 0));
}
forceinline constexpr upx_uint32_t get_be24(const byte *p) noexcept {
typedef upx_uint32_t U;
return (U(p[0]) << 16) | (U(p[1]) << 8) | (U(p[2]) << 0);
return (upx_uint32_t) (((U) p[0] << 16) | ((U) p[1] << 8) | ((U) p[2] << 0));
}
forceinline constexpr upx_uint32_t get_be32(const byte *p) noexcept {
typedef upx_uint32_t U;
return (U(p[0]) << 24) | (U(p[1]) << 16) | (U(p[2]) << 8) | (U(p[3]) << 0);
return (upx_uint32_t) (((U) p[0] << 24) | ((U) p[1] << 16) | ((U) p[2] << 8) | ((U) p[3] << 0));
}
forceinline constexpr upx_uint64_t get_be64(const byte *p) noexcept {
typedef upx_uint64_t U;
return (U(p[0]) << 56) | (U(p[1]) << 48) | (U(p[2]) << 40) | (U(p[3]) << 32) | (U(p[4]) << 24) |
(U(p[5]) << 16) | (U(p[6]) << 8) | (U(p[7]) << 0);
return (upx_uint64_t) (((U) p[0] << 56) | ((U) p[1] << 48) | ((U) p[2] << 40) |
((U) p[3] << 32) | ((U) p[4] << 24) | ((U) p[5] << 16) |
((U) p[6] << 8) | ((U) p[7] << 0));
}
forceinline constexpr void set_be16(byte *p, upx_uint16_t v) noexcept {
p[0] = byte((v >> 8) & 0xff);
p[1] = byte((v >> 0) & 0xff);
p[0] = (byte) ((v >> 8) & 0xff);
p[1] = (byte) ((v >> 0) & 0xff);
}
forceinline constexpr void set_be24(byte *p, upx_uint32_t v) noexcept {
p[0] = byte((v >> 16) & 0xff);
p[1] = byte((v >> 8) & 0xff);
p[2] = byte((v >> 0) & 0xff);
p[0] = (byte) ((v >> 16) & 0xff);
p[1] = (byte) ((v >> 8) & 0xff);
p[2] = (byte) ((v >> 0) & 0xff);
}
forceinline constexpr void set_be32(byte *p, upx_uint32_t v) noexcept {
p[0] = byte((v >> 24) & 0xff);
p[1] = byte((v >> 16) & 0xff);
p[2] = byte((v >> 8) & 0xff);
p[3] = byte((v >> 0) & 0xff);
p[0] = (byte) ((v >> 24) & 0xff);
p[1] = (byte) ((v >> 16) & 0xff);
p[2] = (byte) ((v >> 8) & 0xff);
p[3] = (byte) ((v >> 0) & 0xff);
}
forceinline constexpr void set_be64(byte *p, upx_uint64_t v) noexcept {
p[0] = byte((v >> 56) & 0xff);
p[1] = byte((v >> 48) & 0xff);
p[2] = byte((v >> 40) & 0xff);
p[3] = byte((v >> 32) & 0xff);
p[4] = byte((v >> 24) & 0xff);
p[5] = byte((v >> 16) & 0xff);
p[6] = byte((v >> 8) & 0xff);
p[7] = byte((v >> 0) & 0xff);
p[0] = (byte) ((v >> 56) & 0xff);
p[1] = (byte) ((v >> 48) & 0xff);
p[2] = (byte) ((v >> 40) & 0xff);
p[3] = (byte) ((v >> 32) & 0xff);
p[4] = (byte) ((v >> 24) & 0xff);
p[5] = (byte) ((v >> 16) & 0xff);
p[6] = (byte) ((v >> 8) & 0xff);
p[7] = (byte) ((v >> 0) & 0xff);
}
forceinline constexpr upx_uint16_t get_le16(const byte *p) noexcept {
typedef upx_uint16_t U;
return (U(p[0]) << 0) | (U(p[1]) << 8);
typedef unsigned U;
return (upx_uint16_t) (((U) p[0] << 0) | ((U) p[1] << 8));
}
forceinline constexpr upx_uint32_t get_le24(const byte *p) noexcept {
typedef upx_uint32_t U;
return (U(p[0]) << 0) | (U(p[1]) << 8) | (U(p[2]) << 16);
return (upx_uint32_t) (((U) p[0] << 0) | ((U) p[1] << 8) | ((U) p[2] << 16));
}
forceinline constexpr upx_uint32_t get_le32(const byte *p) noexcept {
typedef upx_uint32_t U;
return (U(p[0]) << 0) | (U(p[1]) << 8) | (U(p[2]) << 16) | (U(p[3]) << 24);
return (upx_uint32_t) (((U) p[0] << 0) | ((U) p[1] << 8) | ((U) p[2] << 16) | ((U) p[3] << 24));
}
forceinline constexpr upx_uint64_t get_le64(const byte *p) noexcept {
typedef upx_uint64_t U;
return (U(p[0]) << 0) | (U(p[1]) << 8) | (U(p[2]) << 16) | (U(p[3]) << 24) | (U(p[4]) << 32) |
(U(p[5]) << 40) | (U(p[6]) << 48) | (U(p[7]) << 56);
return (upx_uint64_t) (((U) p[0] << 0) | ((U) p[1] << 8) | ((U) p[2] << 16) | ((U) p[3] << 24) |
((U) p[4] << 32) | ((U) p[5] << 40) | ((U) p[6] << 48) |
((U) p[7] << 56));
}
forceinline constexpr void set_le16(byte *p, upx_uint16_t v) noexcept {
p[0] = byte((v >> 0) & 0xff);
p[1] = byte((v >> 8) & 0xff);
}
forceinline constexpr void set_le32(byte *p, upx_uint32_t v) noexcept {
p[0] = byte((v >> 0) & 0xff);
p[1] = byte((v >> 8) & 0xff);
p[2] = byte((v >> 16) & 0xff);
p[3] = byte((v >> 24) & 0xff);
p[0] = (byte) ((v >> 0) & 0xff);
p[1] = (byte) ((v >> 8) & 0xff);
}
forceinline constexpr void set_le24(byte *p, upx_uint32_t v) noexcept {
p[0] = byte((v >> 0) & 0xff);
p[1] = byte((v >> 8) & 0xff);
p[2] = byte((v >> 16) & 0xff);
p[0] = (byte) ((v >> 0) & 0xff);
p[1] = (byte) ((v >> 8) & 0xff);
p[2] = (byte) ((v >> 16) & 0xff);
}
forceinline constexpr void set_le32(byte *p, upx_uint32_t v) noexcept {
p[0] = (byte) ((v >> 0) & 0xff);
p[1] = (byte) ((v >> 8) & 0xff);
p[2] = (byte) ((v >> 16) & 0xff);
p[3] = (byte) ((v >> 24) & 0xff);
}
forceinline constexpr void set_le64(byte *p, upx_uint64_t v) noexcept {
p[0] = byte((v >> 0) & 0xff);
p[1] = byte((v >> 8) & 0xff);
p[2] = byte((v >> 16) & 0xff);
p[3] = byte((v >> 24) & 0xff);
p[4] = byte((v >> 32) & 0xff);
p[5] = byte((v >> 40) & 0xff);
p[6] = byte((v >> 48) & 0xff);
p[7] = byte((v >> 56) & 0xff);
p[0] = (byte) ((v >> 0) & 0xff);
p[1] = (byte) ((v >> 8) & 0xff);
p[2] = (byte) ((v >> 16) & 0xff);
p[3] = (byte) ((v >> 24) & 0xff);
p[4] = (byte) ((v >> 32) & 0xff);
p[5] = (byte) ((v >> 40) & 0xff);
p[6] = (byte) ((v >> 48) & 0xff);
p[7] = (byte) ((v >> 56) & 0xff);
}
forceinline constexpr upx_uint16_t get_ne16(const byte *p) noexcept {