mirror of
https://github.com/yuzu-emu/yuzu-mainline
synced 2024-11-26 18:53:20 +00:00
Merge pull request #8560 from liamwhite/bitfield-may-alias
common: fix bitfield aliasing on GCC/Clang
This commit is contained in:
commit
93a4ca11fa
1 changed files with 9 additions and 0 deletions
|
@ -146,7 +146,16 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void Assign(const T& value) {
|
constexpr void Assign(const T& value) {
|
||||||
|
#ifdef _MSC_VER
|
||||||
storage = static_cast<StorageType>((storage & ~mask) | FormatValue(value));
|
storage = static_cast<StorageType>((storage & ~mask) | FormatValue(value));
|
||||||
|
#else
|
||||||
|
// Explicitly reload with memcpy to avoid compiler aliasing quirks
|
||||||
|
// regarding optimization: GCC/Clang clobber chained stores to
|
||||||
|
// different bitfields in the same struct with the last value.
|
||||||
|
StorageTypeWithEndian storage_;
|
||||||
|
std::memcpy(&storage_, &storage, sizeof(storage_));
|
||||||
|
storage = static_cast<StorageType>((storage_ & ~mask) | FormatValue(value));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr T Value() const {
|
[[nodiscard]] constexpr T Value() const {
|
||||||
|
|
Loading…
Reference in a new issue