mirror of
				https://git.tardis.systems/mirrors/yuzu
				synced 2025-11-04 04:34:07 +01:00 
			
		
		
		
	common: fix bitfield aliasing on GCC/Clang
This commit is contained in:
		
							parent
							
								
									313f047f97
								
							
						
					
					
						commit
						a1c1ad096d
					
				@ -146,7 +146,16 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    constexpr void Assign(const T& value) {
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
        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 {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user