Resolve [-Wclass-memaccess]

This commit is contained in:
Minty-Meeo
2023-03-23 12:49:09 -05:00
committed by get
parent 2bb619a508
commit 678c93589a
6 changed files with 22 additions and 56 deletions

View File

@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include <mutex> #include <mutex>
#include <type_traits>
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -101,14 +102,9 @@ void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file,
part_start = offset; part_start = offset;
// Copy cpmem now, because end_of_primitives isn't triggered until the first opcode after // Copy cpmem now, because end_of_primitives isn't triggered until the first opcode after
// primitive data, and the first opcode might update cpmem // primitive data, and the first opcode might update cpmem
#ifdef __GNUC__ static_assert(std::is_trivially_copyable_v<CPState>);
#pragma GCC diagnostic push std::memcpy(static_cast<void*>(&cpmem), static_cast<const void*>(&analyzer.m_cpmem),
#pragma GCC diagnostic ignored "-Wclass-memaccess" sizeof(CPState));
#endif
std::memcpy(&cpmem, &analyzer.m_cpmem, sizeof(CPState));
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
} }
if (analyzer.m_end_of_primitives) if (analyzer.m_end_of_primitives)
{ {

View File

@ -61,14 +61,7 @@ MemoryInterfaceManager::~MemoryInterfaceManager() = default;
void MemoryInterfaceManager::Init() void MemoryInterfaceManager::Init()
{ {
static_assert(std::is_trivially_copyable_v<MIMemStruct>); static_assert(std::is_trivially_copyable_v<MIMemStruct>);
#ifdef __GNUC__ std::memset(static_cast<void*>(&m_mi_mem), 0, sizeof(MIMemStruct));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#endif
std::memset(&m_mi_mem, 0, sizeof(MIMemStruct));
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
} }
void MemoryInterfaceManager::Shutdown() void MemoryInterfaceManager::Shutdown()

View File

@ -136,14 +136,8 @@ static bool DeserializeExtensionState(DesiredWiimoteState* state,
return false; return false;
auto& e = state->extension.data.emplace<T>(); auto& e = state->extension.data.emplace<T>();
static_assert(std::is_trivially_copyable_v<T>); static_assert(std::is_trivially_copyable_v<T>);
#ifdef __GNUC__ std::memcpy(static_cast<void*>(&e), static_cast<const void*>(&serialized.data[offset]),
#pragma GCC diagnostic push sizeof(T));
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#endif
std::memcpy(&e, &serialized.data[offset], sizeof(T));
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
return true; return true;
} }

View File

@ -4,6 +4,7 @@
#include "VideoCommon/CPMemory.h" #include "VideoCommon/CPMemory.h"
#include <cstring> #include <cstring>
#include <type_traits>
#include "Common/ChunkFile.h" #include "Common/ChunkFile.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
@ -17,14 +18,9 @@ CPState g_preprocess_cp_state;
void CopyPreprocessCPStateFromMain() void CopyPreprocessCPStateFromMain()
{ {
#ifdef __GNUC__ static_assert(std::is_trivially_copyable_v<CPState>);
#pragma GCC diagnostic push std::memcpy(static_cast<void*>(&g_preprocess_cp_state),
#pragma GCC diagnostic ignored "-Wclass-memaccess" static_cast<const void*>(&g_main_cp_state), sizeof(CPState));
#endif
std::memcpy(&g_preprocess_cp_state, &g_main_cp_state, sizeof(CPState));
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
} }
std::pair<std::string, std::string> GetCPRegInfo(u8 cmd, u32 value) std::pair<std::string, std::string> GetCPRegInfo(u8 cmd, u32 value)

View File

@ -608,14 +608,10 @@ AbstractPipelineConfig ShaderCache::GetGXPipelineConfig(
static GXPipelineUid ApplyDriverBugs(const GXPipelineUid& in) static GXPipelineUid ApplyDriverBugs(const GXPipelineUid& in)
{ {
GXPipelineUid out; GXPipelineUid out;
#ifdef __GNUC__ // TODO: static_assert(std::is_trivially_copyable_v<GXPipelineUid>);
#pragma GCC diagnostic push // GXPipelineUid is not trivially copyable because RasterizationState and BlendingState aren't
#pragma GCC diagnostic ignored "-Wclass-memaccess" // either, but we can pretend it is for now. This will be improved after PR #10848 is finished.
#endif memcpy(static_cast<void*>(&out), static_cast<const void*>(&in), sizeof(out)); // copy padding
memcpy(&out, &in, sizeof(out)); // copy padding
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
pixel_shader_uid_data* ps = out.ps_uid.GetUidData(); pixel_shader_uid_data* ps = out.ps_uid.GetUidData();
BlendingState& blend = out.blending_state; BlendingState& blend = out.blending_state;
@ -785,14 +781,10 @@ ShaderCache::GetGXPipelineConfig(const GXPipelineUid& config_in)
static GXUberPipelineUid ApplyDriverBugs(const GXUberPipelineUid& in) static GXUberPipelineUid ApplyDriverBugs(const GXUberPipelineUid& in)
{ {
GXUberPipelineUid out; GXUberPipelineUid out;
#ifdef __GNUC__ // TODO: static_assert(std::is_trivially_copyable_v<GXUberPipelineUid>);
#pragma GCC diagnostic push // GXUberPipelineUid is not trivially copyable because RasterizationState and BlendingState aren't
#pragma GCC diagnostic ignored "-Wclass-memaccess" // either, but we can pretend it is for now. This will be improved after PR #10848 is finished.
#endif memcpy(static_cast<void*>(&out), static_cast<const void*>(&in), sizeof(out)); // Copy padding
memcpy(&out, &in, sizeof(out)); // Copy padding
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
if (g_ActiveConfig.backend_info.bSupportsDynamicVertexLoader) if (g_ActiveConfig.backend_info.bSupportsDynamicVertexLoader)
out.vertex_format = nullptr; out.vertex_format = nullptr;

View File

@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <string> #include <string>
#include <type_traits>
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -153,14 +154,8 @@ NativeVertexFormat* GetUberVertexFormat(const PortableVertexDeclaration& decl)
// The padding in the structs can cause the memcmp() in the map to create duplicates. // The padding in the structs can cause the memcmp() in the map to create duplicates.
// Avoid this by initializing the padding to zero. // Avoid this by initializing the padding to zero.
PortableVertexDeclaration new_decl; PortableVertexDeclaration new_decl;
#ifdef __GNUC__ static_assert(std::is_trivially_copyable_v<PortableVertexDeclaration>);
#pragma GCC diagnostic push std::memset(static_cast<void*>(&new_decl), 0, sizeof(new_decl));
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#endif
std::memset(&new_decl, 0, sizeof(new_decl));
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
new_decl.stride = decl.stride; new_decl.stride = decl.stride;
auto MakeDummyAttribute = [](AttributeFormat& attr, ComponentFormat type, int components, auto MakeDummyAttribute = [](AttributeFormat& attr, ComponentFormat type, int components,