Enable -Wstrict-aliasing=1 (GCC)

Fixed partially.
This commit is contained in:
Nekotekina 2021-03-08 23:41:23 +03:00
parent 3990e2d3e6
commit a4fdbf0a88
34 changed files with 141 additions and 81 deletions

64
rpcs3/util/fnv_hash.hpp Normal file
View file

@ -0,0 +1,64 @@
#pragma once
#include "util/types.hpp"
#include <cstring>
namespace rpcs3
{
constexpr usz fnv_seed = 14695981039346656037ull;
constexpr usz fnv_prime = 1099511628211ull;
template <typename T>
static usz hash_base(T value)
{
return static_cast<usz>(value);
}
template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
static inline usz hash64(usz hash_value, T data)
{
hash_value ^= data;
hash_value *= fnv_prime;
return hash_value;
}
template <typename T, typename U>
static usz hash_struct_base(const T& value)
{
// FNV 64-bit
usz result = fnv_seed;
const uchar* bits = reinterpret_cast<const uchar*>(&value);
for (usz n = 0; n < (sizeof(T) / sizeof(U)); ++n)
{
U val{};
std::memcpy(&val, bits + (n * sizeof(U)), sizeof(U));
result = hash64(result, val);
}
return result;
}
template <typename T>
static usz hash_struct(const T& value)
{
static constexpr auto block_sz = sizeof(T);
if constexpr ((block_sz & 0x7) == 0)
{
return hash_struct_base<T, u64>(value);
}
if constexpr ((block_sz & 0x3) == 0)
{
return hash_struct_base<T, u32>(value);
}
if constexpr ((block_sz & 0x1) == 0)
{
return hash_struct_base<T, u16>(value);
}
return hash_struct_base<T, u8>(value);
}
}

View file

@ -258,6 +258,12 @@ namespace stx
r.m_ptr = static_cast<decltype(r.m_ptr)>(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<T>)
{
reinterpret_cast<etype*&>(r) = +ptr->m_data;
r.raw() = +ptr->m_data;
}
else
{
reinterpret_cast<etype*&>(r) = &ptr->m_data;
r.raw() = &ptr->m_data;
}
return r;
@ -370,7 +376,7 @@ namespace stx
};
single_ptr<T> r;
reinterpret_cast<std::remove_extent_t<T>*&>(r) = std::launder(arr);
r.raw() = std::launder(arr);
return r;
}

View file

@ -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