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 // 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") { TEST_CASE("upx::atomic_exchange") {
{ {
upx_int8_t x = -1; upx_int8_t x = -1;
@ -276,12 +288,15 @@ TEST_CASE("upx::atomic_exchange") {
CHECK_EQ(y, (size_t) 0 - 1); CHECK_EQ(y, (size_t) 0 - 1);
} }
{ {
int dummy = -1; const int buf[2] = {101, 202};
int *x = &dummy; const int *ptr_array[2] = {&buf[0], &buf[1]};
int *y = upx::atomic_exchange(&x, (int *) nullptr); assert_noexcept(*ptr_array[0] == 101 && *ptr_array[1] == 202);
CHECK_EQ(x, nullptr); const int *p = upx::atomic_exchange(&ptr_array[0], ptr_array[1]);
CHECK_EQ(y, &dummy); CHECK_EQ(p, buf + 0);
CHECK_EQ(dummy, -1); 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 // TODO later: make sure that this cast is indeed legal
std::atomic<T> *result = ptr_static_cast<std::atomic<T> *>(ptr); std::atomic<T> *result = ptr_static_cast<std::atomic<T> *>(ptr);
static_assert(sizeof(*result) == sizeof(*ptr)); static_assert(sizeof(*result) == sizeof(*ptr));
static_assert(alignof(*result) == alignof(*ptr)); static_assert(alignof(decltype(*result)) == alignof(decltype(*ptr)));
return result; return result;
} }
#endif // WITH_THREADS #endif // WITH_THREADS