From a4fdbf0a8879abead165f350b286409da5d8c8a3 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 8 Mar 2021 23:41:23 +0300 Subject: [PATCH] Enable -Wstrict-aliasing=1 (GCC) Fixed partially. --- Utilities/File.cpp | 4 +- Utilities/JIT.cpp | 1 + Utilities/JIT.h | 2 + Utilities/StrFmt.cpp | 4 +- Utilities/Thread.cpp | 4 +- Utilities/bin_patch.cpp | 39 ++++++++++++------- rpcs3/Emu/CPU/CPUTranslator.h | 1 + rpcs3/Emu/Cell/PPUDisAsm.cpp | 4 +- rpcs3/Emu/Cell/PPUInterpreter.cpp | 8 ++-- rpcs3/Emu/Cell/PPUModule.cpp | 8 +--- rpcs3/Emu/Cell/PPUModule.h | 4 +- rpcs3/Emu/Cell/PPUThread.cpp | 1 + rpcs3/Emu/Cell/SPUDisAsm.cpp | 4 +- rpcs3/Emu/Cell/SPURecompiler.cpp | 1 + rpcs3/Emu/Cell/SPUThread.cpp | 5 ++- rpcs3/Emu/Memory/vm_ptr.h | 12 ++++++ rpcs3/Emu/RSX/Common/BufferUtils.cpp | 42 ++++++++++----------- rpcs3/Emu/RSX/Common/ProgramStateCache.h | 2 +- rpcs3/Emu/RSX/Common/texture_cache.cpp | 2 +- rpcs3/Emu/RSX/GL/GLOverlays.h | 8 ++-- rpcs3/Emu/RSX/RSXThread.cpp | 3 +- rpcs3/Emu/RSX/VK/VKMemAlloc.cpp | 1 + rpcs3/Emu/RSX/VK/VKOverlays.h | 10 ++--- rpcs3/Emu/RSX/VK/VKPipelineCompiler.h | 2 +- rpcs3/Emu/RSX/VK/VKProgramBuffer.h | 3 +- rpcs3/Emu/RSX/rsx_cache.h | 2 +- rpcs3/Emu/RSX/rsx_utils.cpp | 1 + rpcs3/cmake_modules/ConfigureCompiler.cmake | 9 +++++ rpcs3/emucore.vcxproj | 2 +- rpcs3/emucore.vcxproj.filters | 2 +- rpcs3/stb_image.cpp | 1 + Utilities/hash.h => rpcs3/util/fnv_hash.hpp | 17 +++++---- rpcs3/util/shared_ptr.hpp | 12 ++++-- rpcs3/util/yaml.hpp | 1 + 34 files changed, 141 insertions(+), 81 deletions(-) rename Utilities/hash.h => rpcs3/util/fnv_hash.hpp (65%) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index fc45364d49..780341c1e5 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -1301,7 +1301,9 @@ fs::file::file(const std::string& path, bs_t mode) static_assert(sizeof(iovec) == sizeof(iovec_clone), "Weird iovec size"); static_assert(offsetof(iovec, iov_len) == offsetof(iovec_clone, iov_len), "Weird iovec::iov_len offset"); - const auto result = ::writev(m_fd, reinterpret_cast(buffers), buf_count); + iovec arg; + std::memcpy(&arg, buffers, sizeof(arg)); + const auto result = ::writev(m_fd, &arg, buf_count); ensure(result != -1); // "file::write_gather" return result; diff --git a/Utilities/JIT.cpp b/Utilities/JIT.cpp index fbf00feaa8..678971f5c9 100644 --- a/Utilities/JIT.cpp +++ b/Utilities/JIT.cpp @@ -282,6 +282,7 @@ asmjit::Runtime& asmjit::get_global_runtime() #pragma GCC diagnostic ignored "-Wextra" #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif #include "llvm/Support/TargetSelect.h" #include "llvm/Support/FormattedStream.h" diff --git a/Utilities/JIT.h b/Utilities/JIT.h index 2106565509..c4fe904124 100644 --- a/Utilities/JIT.h +++ b/Utilities/JIT.h @@ -14,6 +14,7 @@ #pragma GCC diagnostic ignored "-Wextra" #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wstrict-aliasing" #include #pragma GCC diagnostic pop #endif @@ -180,6 +181,7 @@ inline FT build_function_asm(F&& builder) #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wsuggest-override" #pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wstrict-aliasing" #ifdef __clang__ #pragma clang diagnostic ignored "-Winconsistent-missing-override" #endif diff --git a/Utilities/StrFmt.cpp b/Utilities/StrFmt.cpp index b5f76e7a86..4221f08562 100644 --- a/Utilities/StrFmt.cpp +++ b/Utilities/StrFmt.cpp @@ -344,7 +344,9 @@ struct fmt::cfmt_src template T get(usz index) const { - return *reinterpret_cast(reinterpret_cast(args + index)); + T res{}; + std::memcpy(&res, reinterpret_cast(args + index), sizeof(res)); + return res; } void skip(usz extra) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index a74f2daf73..a442c0a884 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -1261,7 +1261,9 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) no { if (op == X64OP_NONE) { - sig_log.error("decode_x64_reg_op(%p): unsupported opcode: %s", code, *reinterpret_cast*>(code)); + be_t dump; + std::memcpy(&dump, code, sizeof(dump)); + sig_log.error("decode_x64_reg_op(%p): unsupported opcode: %s", code, dump); } }; diff --git a/Utilities/bin_patch.cpp b/Utilities/bin_patch.cpp index 9770a4edda..978ab82b2e 100644 --- a/Utilities/bin_patch.cpp +++ b/Utilities/bin_patch.cpp @@ -547,58 +547,70 @@ static std::basic_string apply_modification(const patch_engine::patch_info& } case patch_type::le16: { - *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); + le_t val = static_cast(p.value.long_value); + std::memcpy(ptr, &val, sizeof(val)); break; } case patch_type::le32: { - *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); + le_t val = static_cast(p.value.long_value); + std::memcpy(ptr, &val, sizeof(val)); break; } case patch_type::lef32: { - *reinterpret_cast*>(ptr) = std::bit_cast(static_cast(p.value.double_value)); + le_t val = static_cast(p.value.double_value); + std::memcpy(ptr, &val, sizeof(val)); break; } case patch_type::le64: { - *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); + le_t val = static_cast(p.value.long_value); + std::memcpy(ptr, &val, sizeof(val)); break; } case patch_type::lef64: { - *reinterpret_cast*>(ptr) = std::bit_cast(p.value.double_value); + le_t val = p.value.double_value; + std::memcpy(ptr, &val, sizeof(val)); break; } case patch_type::be16: { - *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); + be_t val = static_cast(p.value.long_value); + std::memcpy(ptr, &val, sizeof(val)); break; } case patch_type::bd32: { - *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); + be_t val = static_cast(p.value.long_value); + std::memcpy(ptr, &val, sizeof(val)); break; } case patch_type::be32: { - *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); - if (offset % 4 == 0) resval = offset; + be_t val = static_cast(p.value.long_value); + std::memcpy(ptr, &val, sizeof(val)); + if (offset % 4 == 0) + resval = offset; break; } case patch_type::bef32: { - *reinterpret_cast*>(ptr) = std::bit_cast(static_cast(p.value.double_value)); + be_t val = static_cast(p.value.double_value); + std::memcpy(ptr, &val, sizeof(val)); break; } case patch_type::bd64: { - *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); + be_t val = static_cast(p.value.long_value); + std::memcpy(ptr, &val, sizeof(val)); break; } case patch_type::be64: { - *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); + be_t val = static_cast(p.value.long_value); + std::memcpy(ptr, &val, sizeof(val)); if (offset % 4) { @@ -611,7 +623,8 @@ static std::basic_string apply_modification(const patch_engine::patch_info& } case patch_type::bef64: { - *reinterpret_cast*>(ptr) = std::bit_cast(p.value.double_value); + be_t val = p.value.double_value; + std::memcpy(ptr, &val, sizeof(val)); break; } case patch_type::utf8: diff --git a/rpcs3/Emu/CPU/CPUTranslator.h b/rpcs3/Emu/CPU/CPUTranslator.h index 94a8c13602..4e953340d7 100644 --- a/rpcs3/Emu/CPU/CPUTranslator.h +++ b/rpcs3/Emu/CPU/CPUTranslator.h @@ -10,6 +10,7 @@ #pragma GCC diagnostic ignored "-Wextra" #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif #include "llvm/IR/LLVMContext.h" #include "llvm/IR/IRBuilder.h" diff --git a/rpcs3/Emu/Cell/PPUDisAsm.cpp b/rpcs3/Emu/Cell/PPUDisAsm.cpp index 21d5b0d0eb..82cbbb2a04 100644 --- a/rpcs3/Emu/Cell/PPUDisAsm.cpp +++ b/rpcs3/Emu/Cell/PPUDisAsm.cpp @@ -7,7 +7,9 @@ const ppu_decoder s_ppu_disasm; u32 PPUDisAsm::disasm(u32 pc) { dump_pc = pc; - m_op = *reinterpret_cast*>(m_offset + pc); + be_t op{}; + std::memcpy(&op, m_offset + pc, 4); + m_op = op; (this->*(s_ppu_disasm.decode(m_op)))({ m_op }); return 4; } diff --git a/rpcs3/Emu/Cell/PPUInterpreter.cpp b/rpcs3/Emu/Cell/PPUInterpreter.cpp index 3cc2584df0..8b412add38 100644 --- a/rpcs3/Emu/Cell/PPUInterpreter.cpp +++ b/rpcs3/Emu/Cell/PPUInterpreter.cpp @@ -3411,9 +3411,11 @@ bool ppu_interpreter::MFOCRF(ppu_thread& ppu, ppu_opcode_t op) else { // MFCR - auto* lanes = reinterpret_cast*>(+ppu.cr.bits); - const u32 mh = _mm_movemask_epi8(_mm_slli_epi64(lanes[0].value().vi, 7)); - const u32 ml = _mm_movemask_epi8(_mm_slli_epi64(lanes[1].value().vi, 7)); + be_t lane0, lane1; + std::memcpy(&lane0, ppu.cr.bits, sizeof(v128)); + std::memcpy(&lane1, ppu.cr.bits + 16, sizeof(v128)); + const u32 mh = _mm_movemask_epi8(_mm_slli_epi64(lane0.value().vi, 7)); + const u32 ml = _mm_movemask_epi8(_mm_slli_epi64(lane0.value().vi, 7)); ppu.gpr[op.rd] = (mh << 16) | ml; } diff --git a/rpcs3/Emu/Cell/PPUModule.cpp b/rpcs3/Emu/Cell/PPUModule.cpp index 70b0c11caf..6d5a64c9b8 100644 --- a/rpcs3/Emu/Cell/PPUModule.cpp +++ b/rpcs3/Emu/Cell/PPUModule.cpp @@ -344,12 +344,8 @@ static void ppu_initialize_modules(ppu_linkage_info* link) alloc_addr += variable.second.size; } - if (variable.second.var) - { - variable.second.var->set(variable.second.addr); - } - - ppu_loader.trace("Allocated HLE variable %s.%s at 0x%x", _module->name, variable.second.name, variable.second.var->addr()); + *variable.second.var = variable.second.addr; + ppu_loader.trace("Allocated HLE variable %s.%s at 0x%x", _module->name, variable.second.name, *variable.second.var); // Initialize HLE variable if (variable.second.init) diff --git a/rpcs3/Emu/Cell/PPUModule.h b/rpcs3/Emu/Cell/PPUModule.h index ca5c8e4b70..acdb58743b 100644 --- a/rpcs3/Emu/Cell/PPUModule.h +++ b/rpcs3/Emu/Cell/PPUModule.h @@ -54,7 +54,7 @@ struct ppu_static_function struct ppu_static_variable { const char* name; - vm::gvar* var; // Pointer to variable address storage + u32* var; // Pointer to variable address storage void(*init)(); // Variable initialization function u32 size; u32 align; @@ -144,7 +144,7 @@ public: auto& info = access_static_variable(_module, vnid); info.name = name; - info.var = reinterpret_cast*>(Var); + info.var = &Var->raw(); info.init = [] {}; info.size = gvar::alloc_size; info.align = gvar::alloc_align; diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index ac332484e1..5fd63a71f8 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -31,6 +31,7 @@ #pragma GCC diagnostic ignored "-Wextra" #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif #include "llvm/Support/FormattedStream.h" #include "llvm/Support/MemoryBuffer.h" diff --git a/rpcs3/Emu/Cell/SPUDisAsm.cpp b/rpcs3/Emu/Cell/SPUDisAsm.cpp index eac89af5af..9b79fb23c6 100644 --- a/rpcs3/Emu/Cell/SPUDisAsm.cpp +++ b/rpcs3/Emu/Cell/SPUDisAsm.cpp @@ -13,7 +13,9 @@ const spu_decoder s_spu_iflag; u32 SPUDisAsm::disasm(u32 pc) { dump_pc = pc; - m_op = *reinterpret_cast*>(m_offset + pc); + be_t op; + std::memcpy(&op, m_offset + pc, 4); + m_op = op; (this->*(s_spu_disasm.decode(m_op)))({ m_op }); return 4; } diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index 3abc2a1fb1..40d634389e 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -3221,6 +3221,7 @@ void spu_recompiler_base::dump(const spu_program& result, std::string& out) #pragma GCC diagnostic ignored "-Wextra" #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif #include "llvm/ADT/Triple.h" #include "llvm/IR/LegacyPassManager.h" diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 911e02378e..c46c5ce7a8 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -2161,7 +2161,7 @@ void spu_thread::do_dma_transfer(spu_thread* _this, const spu_mfc_cmd& args, u8* auto& res = vm::reservation_acquire(eal); // Lock each bit corresponding to a byte being written, using some free space in reservation memory - auto* bits = reinterpret_cast*>(vm::g_reservations + (eal & 0xff80) / 2 + 16); + auto* bits = reinterpret_cast*>(vm::g_reservations + ((eal & 0xff80) / 2 + 16)); // Get writing mask const u128 wmask = (~u128{} << (eal & 127)) & (~u128{} >> (127 - ((eal + size0 - 1) & 127))); @@ -4735,7 +4735,8 @@ bool spu_thread::capture_local_storage() const for (; pc0; pc0 -= 4) { - const u32 op = *std::launder(reinterpret_cast*>(prog.bin.data() + pc0 - 4)); + be_t op; + std::memcpy(&op, prog.bin.data() + pc0 - 4, 4); // Try to find function entry (if they are placed sequentially search for BI $LR of previous function) if (!op || op == 0x35000000u || s_spu_itype.decode(op) == spu_itype::UNK) diff --git a/rpcs3/Emu/Memory/vm_ptr.h b/rpcs3/Emu/Memory/vm_ptr.h index 91bfa9655b..f7f4500fc2 100644 --- a/rpcs3/Emu/Memory/vm_ptr.h +++ b/rpcs3/Emu/Memory/vm_ptr.h @@ -211,6 +211,12 @@ namespace vm { return vm::try_access(vm::cast(m_addr), const_cast(&_in), sizeof(T), true); } + + // Don't use + auto& raw() + { + return m_addr; + } }; template @@ -262,6 +268,12 @@ namespace vm return vm::cast(m_addr); } + // Don't use + auto& raw() + { + return m_addr; + } + // Callback; defined in PPUCallback.h, passing context is mandatory RT operator()(ppu_thread& ppu, T... args) const; const ppu_func_opd_t& opd() const; diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.cpp b/rpcs3/Emu/RSX/Common/BufferUtils.cpp index b8db764b65..5290732760 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.cpp +++ b/rpcs3/Emu/RSX/Common/BufferUtils.cpp @@ -140,13 +140,12 @@ namespace } } - if (remaining) + for (u32 i = 0; i < remaining; ++i) { - const auto src_ptr2 = reinterpret_cast*>(src_ptr); - const auto dst_ptr2 = reinterpret_cast*>(dst_ptr); - - for (u32 i = 0; i < remaining; ++i) - dst_ptr2[i] = src_ptr2[i]; + be_t val; + std::memcpy(&val, src_ptr + i * sizeof(val), sizeof(val)); + le_t nval = +val; + std::memcpy(dst_ptr + i * sizeof(nval), &nval, sizeof(nval)); } } @@ -218,20 +217,18 @@ namespace const u32 remaining = dword_count % 4; - if (remaining) + for (u32 i = 0; i < remaining; ++i) { - const auto src_ptr2 = reinterpret_cast*>(src_ptr); - const auto dst_ptr2 = reinterpret_cast*>(dst_ptr); + be_t val; + std::memcpy(&val, src_ptr + i * sizeof(val), sizeof(val)); + le_t nval; + std::memcpy(&nval, dst_ptr + i * sizeof(nval), sizeof(nval)); - for (u32 i = 0; i < remaining; ++i) + if (val != nval) { - const u32 data = src_ptr2[i]; - - if (dst_ptr2[i] != data) - { - dst_ptr2[i] = data; - bits_diff = _mm_set1_epi64x(-1); - } + nval = val; + std::memcpy(dst_ptr + i * sizeof(nval), &nval, sizeof(nval)); + bits_diff = _mm_set1_epi64x(-1); } } @@ -283,13 +280,12 @@ namespace } } - if (remaining) + for (u32 i = 0; i < remaining; ++i) { - auto src_ptr2 = reinterpret_cast*>(src_ptr); - auto dst_ptr2 = reinterpret_cast*>(dst_ptr); - - for (u32 i = 0; i < remaining; ++i) - dst_ptr2[i] = src_ptr2[i]; + be_t val; + std::memcpy(&val, src_ptr + i * sizeof(val), sizeof(val)); + le_t nval = +val; + std::memcpy(dst_ptr + i * sizeof(nval), &nval, sizeof(nval)); } } diff --git a/rpcs3/Emu/RSX/Common/ProgramStateCache.h b/rpcs3/Emu/RSX/Common/ProgramStateCache.h index 46b940e599..6620a890d5 100644 --- a/rpcs3/Emu/RSX/Common/ProgramStateCache.h +++ b/rpcs3/Emu/RSX/Common/ProgramStateCache.h @@ -3,10 +3,10 @@ #include "Emu/RSX/RSXFragmentProgram.h" #include "Emu/RSX/RSXVertexProgram.h" -#include "Utilities/hash.h" #include "Utilities/mutex.h" #include "util/logs.hpp" #include "Utilities/span.h" +#include "util/fnv_hash.hpp" #include #include diff --git a/rpcs3/Emu/RSX/Common/texture_cache.cpp b/rpcs3/Emu/RSX/Common/texture_cache.cpp index 832bc0d596..4a91f70784 100644 --- a/rpcs3/Emu/RSX/Common/texture_cache.cpp +++ b/rpcs3/Emu/RSX/Common/texture_cache.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "texture_cache_utils.h" #include "Utilities/address_range.h" -#include "Utilities/hash.h" +#include "util/fnv_hash.hpp" namespace rsx { diff --git a/rpcs3/Emu/RSX/GL/GLOverlays.h b/rpcs3/Emu/RSX/GL/GLOverlays.h index d5c93420b5..b78a3b0981 100644 --- a/rpcs3/Emu/RSX/GL/GLOverlays.h +++ b/rpcs3/Emu/RSX/GL/GLOverlays.h @@ -115,10 +115,10 @@ namespace gl virtual void bind_resources() {} virtual void cleanup_resources() {} - virtual void upload_vertex_data(f32* data, u32 elements_count) + template + void upload_vertex_data(T* data, u32 elements_count) { - elements_count <<= 2; - m_vertex_data_buffer.data(elements_count, data); + m_vertex_data_buffer.data(elements_count * sizeof(T), data); } virtual void emit_geometry() @@ -594,7 +594,7 @@ namespace gl for (auto &cmd : ui.get_compiled().draw_commands) { set_primitive_type(cmd.config.primitives); - upload_vertex_data(reinterpret_cast(cmd.verts.data()), ::size32(cmd.verts) * 4u); + upload_vertex_data(cmd.verts.data(), ::size32(cmd.verts)); num_drawable_elements = ::size32(cmd.verts); GLint texture_read = GL_TRUE; diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index c0341e6244..a4c64fc2f9 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -2169,7 +2169,8 @@ namespace rsx { if (layout.attribute_placement[index] == attribute_buffer_placement::none) { - reinterpret_cast(buffer)[index] = 0; + static constexpr u64 zero = 0; + std::memcpy(buffer + index * 2, &zero, sizeof(zero)); continue; } diff --git a/rpcs3/Emu/RSX/VK/VKMemAlloc.cpp b/rpcs3/Emu/RSX/VK/VKMemAlloc.cpp index f48ee138c6..b25628cb08 100644 --- a/rpcs3/Emu/RSX/VK/VKMemAlloc.cpp +++ b/rpcs3/Emu/RSX/VK/VKMemAlloc.cpp @@ -45,6 +45,7 @@ private: #pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wsuggest-override" #pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wstrict-aliasing" #ifdef __clang__ #pragma clang diagnostic ignored "-Winconsistent-missing-override" #endif diff --git a/rpcs3/Emu/RSX/VK/VKOverlays.h b/rpcs3/Emu/RSX/VK/VKOverlays.h index 4be44f9e66..10a50e3107 100644 --- a/rpcs3/Emu/RSX/VK/VKOverlays.h +++ b/rpcs3/Emu/RSX/VK/VKOverlays.h @@ -14,8 +14,8 @@ #include "../Overlays/overlays.h" -#include "Utilities/hash.h" #include +#include "util/fnv_hash.hpp" #define VK_OVERLAY_MAX_DRAW_CALLS 1024 @@ -180,11 +180,12 @@ namespace vk return {}; } - void upload_vertex_data(f32 *data, u32 count) + template + void upload_vertex_data(T* data, u32 count) { check_heap(); - const auto size = count * sizeof(f32); + const auto size = count * sizeof(T); m_vao_offset = static_cast(m_vao.alloc<16>(size)); auto dst = m_vao.map(m_vao_offset, size); std::memcpy(dst, data, size); @@ -812,9 +813,8 @@ namespace vk for (auto &command : ui.get_compiled().draw_commands) { num_drawable_elements = static_cast(command.verts.size()); - const u32 value_count = num_drawable_elements * 4; - upload_vertex_data(reinterpret_cast(command.verts.data()), value_count); + upload_vertex_data(command.verts.data(), num_drawable_elements); set_primitive_type(command.config.primitives); m_skip_texture_read = false; diff --git a/rpcs3/Emu/RSX/VK/VKPipelineCompiler.h b/rpcs3/Emu/RSX/VK/VKPipelineCompiler.h index e1f6812bbf..482100180e 100644 --- a/rpcs3/Emu/RSX/VK/VKPipelineCompiler.h +++ b/rpcs3/Emu/RSX/VK/VKPipelineCompiler.h @@ -1,9 +1,9 @@ #pragma once #include "../rsx_utils.h" -#include "Utilities/hash.h" #include "Utilities/lockless.h" #include "VKProgramPipeline.h" #include "vkutils/graphics_pipeline_state.hpp" +#include "util/fnv_hash.hpp" namespace vk { diff --git a/rpcs3/Emu/RSX/VK/VKProgramBuffer.h b/rpcs3/Emu/RSX/VK/VKProgramBuffer.h index c173adf18a..f877c0409a 100644 --- a/rpcs3/Emu/RSX/VK/VKProgramBuffer.h +++ b/rpcs3/Emu/RSX/VK/VKProgramBuffer.h @@ -2,10 +2,11 @@ #include "VKVertexProgram.h" #include "VKFragmentProgram.h" #include "../Common/ProgramStateCache.h" -#include "Utilities/hash.h" #include "VKRenderPass.h" #include "VKPipelineCompiler.h" +#include "util/fnv_hash.hpp" + namespace vk { struct VKTraits diff --git a/rpcs3/Emu/RSX/rsx_cache.h b/rpcs3/Emu/RSX/rsx_cache.h index 713e0c7ce9..6e1253807a 100644 --- a/rpcs3/Emu/RSX/rsx_cache.h +++ b/rpcs3/Emu/RSX/rsx_cache.h @@ -1,5 +1,4 @@ #pragma once -#include "Utilities/hash.h" #include "Utilities/File.h" #include "Utilities/lockless.h" #include "Utilities/Thread.h" @@ -17,6 +16,7 @@ #include "util/vm.hpp" #include "util/sysinfo.hpp" +#include "util/fnv_hash.hpp" namespace rsx { diff --git a/rpcs3/Emu/RSX/rsx_utils.cpp b/rpcs3/Emu/RSX/rsx_utils.cpp index a84269b58e..cdaeb189fd 100644 --- a/rpcs3/Emu/RSX/rsx_utils.cpp +++ b/rpcs3/Emu/RSX/rsx_utils.cpp @@ -12,6 +12,7 @@ #pragma GCC diagnostic ignored "-Wall" #pragma GCC diagnostic ignored "-Wextra" #pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif extern "C" { diff --git a/rpcs3/cmake_modules/ConfigureCompiler.cmake b/rpcs3/cmake_modules/ConfigureCompiler.cmake index 18c4485cf3..a32f6f7f0a 100644 --- a/rpcs3/cmake_modules/ConfigureCompiler.cmake +++ b/rpcs3/cmake_modules/ConfigureCompiler.cmake @@ -35,14 +35,23 @@ else() add_compile_options(-Wunused-parameter) add_compile_options(-Wignored-qualifiers) #add_compile_options(-Wdeprecated-copy) + #add_compile_options(-Wtautological-compare) + #add_compile_options(-Wshadow) + #add_compile_options(-Wconversion) + #add_compile_options(-Wpadded) add_compile_options(-Wempty-body) + add_compile_options(-Wstrict-aliasing=1) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Werror=inconsistent-missing-override) elseif(CMAKE_COMPILER_IS_GNUCXX) add_compile_options(-Werror=suggest-override) add_compile_options(-Wclobbered) add_compile_options(-Wcast-function-type) + #add_compile_options(-Wduplicated-branches) + #add_compile_options(-Wduplicated-cond) + #add_compile_options(-Wredundant-decls) endif() #TODO Clean the code so these are removed diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index 3e68f02834..0956485e6d 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -499,7 +499,7 @@ - + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index d76a51e5b5..c865ff2d7a 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -1645,7 +1645,7 @@ Emu\GPU\RSX\Common - + Utilities diff --git a/rpcs3/stb_image.cpp b/rpcs3/stb_image.cpp index 65f64baea2..361b94e48a 100644 --- a/rpcs3/stb_image.cpp +++ b/rpcs3/stb_image.cpp @@ -16,6 +16,7 @@ #pragma GCC diagnostic ignored "-Wall" #pragma GCC diagnostic ignored "-Wextra" #pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wstrict-aliasing" #include #include #pragma GCC diagnostic pop diff --git a/Utilities/hash.h b/rpcs3/util/fnv_hash.hpp similarity index 65% rename from Utilities/hash.h rename to rpcs3/util/fnv_hash.hpp index c91cc9a707..d7ebfe74da 100644 --- a/Utilities/hash.h +++ b/rpcs3/util/fnv_hash.hpp @@ -1,42 +1,45 @@ #pragma once #include "util/types.hpp" +#include namespace rpcs3 { constexpr usz fnv_seed = 14695981039346656037ull; constexpr usz fnv_prime = 1099511628211ull; - template + template static usz hash_base(T value) { return static_cast(value); } - template::value, bool>> - static inline usz hash64(usz hash_value, const T data) + template ::value>> + static inline usz hash64(usz hash_value, T data) { hash_value ^= data; hash_value *= fnv_prime; return hash_value; } - template + template static usz hash_struct_base(const T& value) { // FNV 64-bit usz result = fnv_seed; - const U *bits = reinterpret_cast(&value); + const uchar* bits = reinterpret_cast(&value); for (usz n = 0; n < (sizeof(T) / sizeof(U)); ++n) { - result = hash64(result, bits[n]); + U val{}; + std::memcpy(&val, bits + (n * sizeof(U)), sizeof(U)); + result = hash64(result, val); } return result; } - template + template static usz hash_struct(const T& value) { static constexpr auto block_sz = sizeof(T); diff --git a/rpcs3/util/shared_ptr.hpp b/rpcs3/util/shared_ptr.hpp index 55c452fa84..6d5c975b10 100644 --- a/rpcs3/util/shared_ptr.hpp +++ b/rpcs3/util/shared_ptr.hpp @@ -258,6 +258,12 @@ namespace stx r.m_ptr = static_cast(std::exchange(m_ptr, nullptr)); return r; } + + // Raw access for make_single() + auto& raw() noexcept + { + return m_ptr; + } }; #ifndef _MSC_VER @@ -302,11 +308,11 @@ namespace stx if constexpr (std::is_array_v) { - reinterpret_cast(r) = +ptr->m_data; + r.raw() = +ptr->m_data; } else { - reinterpret_cast(r) = &ptr->m_data; + r.raw() = &ptr->m_data; } return r; @@ -370,7 +376,7 @@ namespace stx }; single_ptr r; - reinterpret_cast*&>(r) = std::launder(arr); + r.raw() = std::launder(arr); return r; } diff --git a/rpcs3/util/yaml.hpp b/rpcs3/util/yaml.hpp index 9b9d8167a4..18fdad21a1 100644 --- a/rpcs3/util/yaml.hpp +++ b/rpcs3/util/yaml.hpp @@ -13,6 +13,7 @@ #pragma GCC diagnostic ignored "-Wextra" #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wattributes" +#pragma GCC diagnostic ignored "-Wstrict-aliasing" #include "yaml-cpp/yaml.h" #pragma GCC diagnostic pop #endif