From 4704c032096540fa452d4dc7e12e7390b63f6a92 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sun, 1 Jun 2025 20:45:05 +0200 Subject: [PATCH] Fix some static analysis warnings, including c-style cast --- Utilities/Thread.h | 4 ++-- Utilities/transactional_storage.h | 3 +-- rpcs3/Emu/Memory/vm_reservation.h | 3 ++- rpcs3/Emu/NP/np_allocator.h | 2 +- rpcs3/util/asm.hpp | 2 +- rpcs3/util/atomic.cpp | 4 ++-- rpcs3/util/atomic.hpp | 8 ++++---- rpcs3/util/bless.hpp | 2 ++ rpcs3/util/cpu_stats.cpp | 2 +- 9 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Utilities/Thread.h b/Utilities/Thread.h index 52096a2702..6dc2dc8cf6 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -96,7 +96,7 @@ class thread_future thread_future* prev{}; protected: - atomic_t exec{}; + atomic_t exec{}; atomic_t done{0}; @@ -389,7 +389,7 @@ public: : m_args(std::forward(args)...) , m_func(std::forward(func)) { - thread_future::exec.raw() = +[](thread_base* tb, thread_future* tf) + thread_future::exec.raw() = +[](const thread_base* tb, thread_future* tf) { const auto _this = static_cast(tf); diff --git a/Utilities/transactional_storage.h b/Utilities/transactional_storage.h index 55e8aa9f95..1be923233e 100644 --- a/Utilities/transactional_storage.h +++ b/Utilities/transactional_storage.h @@ -84,9 +84,8 @@ public: transactional_storage& operator=(const transactional_storage&) = delete; transactional_storage(transactional_storage&& other) + : pool(std::move(other.pool)) { - pool = std::move(other.pool); - std::unique_lock lock_other{other.current_mutex}; const std::shared_ptr other_current = other.current; other.current = nullptr; diff --git a/rpcs3/Emu/Memory/vm_reservation.h b/rpcs3/Emu/Memory/vm_reservation.h index c9d2e0c50a..af402249bf 100644 --- a/rpcs3/Emu/Memory/vm_reservation.h +++ b/rpcs3/Emu/Memory/vm_reservation.h @@ -81,7 +81,8 @@ namespace vm static inline atomic_t* reservation_notifier_begin_wait(u32 raddr, u64 rtime) { - atomic_t& waiter = *reservation_notifier(raddr).first; + const auto notifiers = reservation_notifier(raddr); + atomic_t& waiter = *notifiers.first; waiter.atomic_op([](reservation_waiter_t& value) { diff --git a/rpcs3/Emu/NP/np_allocator.h b/rpcs3/Emu/NP/np_allocator.h index 25c65ea2e4..ee8017cb72 100644 --- a/rpcs3/Emu/NP/np_allocator.h +++ b/rpcs3/Emu/NP/np_allocator.h @@ -59,7 +59,7 @@ namespace np u32 last_free = 0; bool found_space = false; - for (auto& a : m_allocs) + for (const auto& a : m_allocs) { if ((a.first - last_free) >= alloc_size) { diff --git a/rpcs3/util/asm.hpp b/rpcs3/util/asm.hpp index 947aa4f54a..14eaa1409d 100644 --- a/rpcs3/util/asm.hpp +++ b/rpcs3/util/asm.hpp @@ -135,7 +135,7 @@ namespace utils #endif } - constexpr void prefetch_write(void* ptr) + constexpr void prefetch_write(const void* ptr) { if (std::is_constant_evaluated()) { diff --git a/rpcs3/util/atomic.cpp b/rpcs3/util/atomic.cpp index c8e76cbf17..67f48f8dc7 100644 --- a/rpcs3/util/atomic.cpp +++ b/rpcs3/util/atomic.cpp @@ -15,12 +15,12 @@ namespace utils { u128 __vectorcall atomic_load16(const void* ptr) { - return std::bit_cast(_mm_load_si128((__m128i*)ptr)); + return std::bit_cast(_mm_load_si128(static_cast(ptr))); } void __vectorcall atomic_store16(void* ptr, u128 value) { - _mm_store_si128((__m128i*)ptr, std::bit_cast<__m128i>(value)); + _mm_store_si128(static_cast<__m128i*>(ptr), std::bit_cast<__m128i>(value)); } } #endif diff --git a/rpcs3/util/atomic.hpp b/rpcs3/util/atomic.hpp index 80d9e34f9d..4503eaac61 100644 --- a/rpcs3/util/atomic.hpp +++ b/rpcs3/util/atomic.hpp @@ -479,7 +479,7 @@ struct atomic_storage #endif #if defined(_M_X64) && defined(_MSC_VER) - return _interlockedbittestandset((long*)dst, bit) != 0; + return _interlockedbittestandset(reinterpret_cast(dst), bit) != 0; #elif defined(ARCH_X64) bool result; __asm__ volatile ("lock btsl %2, 0(%1)\n" : "=@ccc" (result) : "r" (dst), "Ir" (bit) : "cc", "memory"); @@ -506,7 +506,7 @@ struct atomic_storage #endif #if defined(_M_X64) && defined(_MSC_VER) - return _interlockedbittestandreset((long*)dst, bit) != 0; + return _interlockedbittestandreset(reinterpret_cast(dst), bit) != 0; #elif defined(ARCH_X64) bool result; __asm__ volatile ("lock btrl %2, 0(%1)\n" : "=@ccc" (result) : "r" (dst), "Ir" (bit) : "cc", "memory"); @@ -536,9 +536,9 @@ struct atomic_storage while (true) { // Keep trying until we actually invert desired bit - if (!_bittest((long*)dst, bit) && !_interlockedbittestandset((long*)dst, bit)) + if (!_bittest(reinterpret_cast(dst), bit) && !_interlockedbittestandset(reinterpret_cast(dst), bit)) return false; - if (_interlockedbittestandreset((long*)dst, bit)) + if (_interlockedbittestandreset(reinterpret_cast(dst), bit)) return true; } #elif defined(ARCH_X64) diff --git a/rpcs3/util/bless.hpp b/rpcs3/util/bless.hpp index 49ffa8facb..af2f8d32f3 100644 --- a/rpcs3/util/bless.hpp +++ b/rpcs3/util/bless.hpp @@ -16,6 +16,8 @@ namespace utils T* result; __asm__("mov %0, %1" : "=r" (result) : "r" (ptr) : "memory"); return result; +#else +#error "Missing utils::bless() implementation" #endif } } diff --git a/rpcs3/util/cpu_stats.cpp b/rpcs3/util/cpu_stats.cpp index 42c5304bea..8203d1977b 100644 --- a/rpcs3/util/cpu_stats.cpp +++ b/rpcs3/util/cpu_stats.cpp @@ -444,7 +444,7 @@ namespace utils if (proc_dir) { // proc available, iterate through tasks and count them - struct dirent* entry; + const struct dirent* entry; while ((entry = readdir(proc_dir)) != NULL) { if (entry->d_name[0] == '.')