1
0
mirror of https://github.com/upx/upx.git synced 2025-08-11 22:52:30 +08:00

src: fix compilation with clang

This commit is contained in:
Markus F.X.J. Oberhumer
2024-05-07 12:33:55 +02:00
parent 3d82f0cfe1
commit 76b2cec8ee
2 changed files with 22 additions and 7 deletions

View File

@ -250,6 +250,18 @@ struct Z2_X2 : public X2 {
// util
**************************************************************************/
#if WITH_THREADS
TEST_CASE("upx::ptr_std_atomic_cast") {
(void) upx::ptr_std_atomic_cast((upx_int8_t *) nullptr);
(void) upx::ptr_std_atomic_cast((upx_int16_t *) nullptr);
(void) upx::ptr_std_atomic_cast((upx_int32_t *) nullptr);
(void) upx::ptr_std_atomic_cast((int *) nullptr);
(void) upx::ptr_std_atomic_cast((long *) nullptr);
(void) upx::ptr_std_atomic_cast((size_t *) nullptr);
(void) upx::ptr_std_atomic_cast((void **) nullptr);
}
#endif
TEST_CASE("upx::atomic_exchange") {
{
upx_int8_t x = -1;
@ -276,12 +288,15 @@ TEST_CASE("upx::atomic_exchange") {
CHECK_EQ(y, (size_t) 0 - 1);
}
{
int dummy = -1;
int *x = &dummy;
int *y = upx::atomic_exchange(&x, (int *) nullptr);
CHECK_EQ(x, nullptr);
CHECK_EQ(y, &dummy);
CHECK_EQ(dummy, -1);
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);
}
}

View File

@ -194,7 +194,7 @@ forceinline std::atomic<T> *ptr_std_atomic_cast(T *ptr) noexcept {
// TODO later: make sure that this cast is indeed legal
std::atomic<T> *result = ptr_static_cast<std::atomic<T> *>(ptr);
static_assert(sizeof(*result) == sizeof(*ptr));
static_assert(alignof(*result) == alignof(*ptr));
static_assert(alignof(decltype(*result)) == alignof(decltype(*ptr)));
return result;
}
#endif // WITH_THREADS