Merge pull request #1013 from lassipulkkinen/unaligned_read_may_alias

Use may_alias with unaligned reads to fix miscompilation on GCC
This commit is contained in:
Yann Collet
2025-06-18 16:52:07 -07:00
committed by GitHub

View File

@@ -2661,7 +2661,7 @@ typedef union { xxh_u32 u32; } __attribute__((__packed__)) unalign;
#endif
static xxh_u32 XXH_read32(const void* ptr)
{
typedef __attribute__((__aligned__(1))) xxh_u32 xxh_unalign32;
typedef __attribute__((__aligned__(1))) __attribute__((__may_alias__)) xxh_u32 xxh_unalign32;
return *((const xxh_unalign32*)ptr);
}
@@ -3374,7 +3374,7 @@ typedef union { xxh_u32 u32; xxh_u64 u64; } __attribute__((__packed__)) unalign6
#endif
static xxh_u64 XXH_read64(const void* ptr)
{
typedef __attribute__((__aligned__(1))) xxh_u64 xxh_unalign64;
typedef __attribute__((__aligned__(1))) __attribute__((__may_alias__)) xxh_u64 xxh_unalign64;
return *((const xxh_unalign64*)ptr);
}