diff options
| author | 2022-07-15 22:16:52 -0700 | |
|---|---|---|
| committer | 2022-07-15 22:16:52 -0700 | |
| commit | 93a4ca11fa976a71cfd4912900b5f98993c930d4 (patch) | |
| tree | 4faff3821fd0905e05de813b7f70cdf6b550f3ff | |
| parent | Merge pull request #8587 from merryhime/padding-unused (diff) | |
| parent | common: fix bitfield aliasing on GCC/Clang (diff) | |
| download | yuzu-93a4ca11fa976a71cfd4912900b5f98993c930d4.tar.gz yuzu-93a4ca11fa976a71cfd4912900b5f98993c930d4.tar.xz yuzu-93a4ca11fa976a71cfd4912900b5f98993c930d4.zip | |
Merge pull request #8560 from liamwhite/bitfield-may-alias
common: fix bitfield aliasing on GCC/Clang
Diffstat (limited to '')
| -rw-r--r-- | src/common/bit_field.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/common/bit_field.h b/src/common/bit_field.h index 16d805694..7e1df62b1 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h | |||
| @@ -146,7 +146,16 @@ public: | |||
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | constexpr void Assign(const T& value) { | 148 | constexpr void Assign(const T& value) { |
| 149 | #ifdef _MSC_VER | ||
| 149 | storage = static_cast<StorageType>((storage & ~mask) | FormatValue(value)); | 150 | storage = static_cast<StorageType>((storage & ~mask) | FormatValue(value)); |
| 151 | #else | ||
| 152 | // Explicitly reload with memcpy to avoid compiler aliasing quirks | ||
| 153 | // regarding optimization: GCC/Clang clobber chained stores to | ||
| 154 | // different bitfields in the same struct with the last value. | ||
| 155 | StorageTypeWithEndian storage_; | ||
| 156 | std::memcpy(&storage_, &storage, sizeof(storage_)); | ||
| 157 | storage = static_cast<StorageType>((storage_ & ~mask) | FormatValue(value)); | ||
| 158 | #endif | ||
| 150 | } | 159 | } |
| 151 | 160 | ||
| 152 | [[nodiscard]] constexpr T Value() const { | 161 | [[nodiscard]] constexpr T Value() const { |