Disable ubsan's integer sanitizer warnings

They crop up on valid per the standard (but sometimes bogus) uses
of modular arithmetic on unsigned integers, such as in hash functions.
This commit is contained in:
Jean-Michaël Celerier
2025-07-02 23:22:10 -04:00
committed by Martin Leitner-Ankerl
parent f9bd51faca
commit b4802df020

View File

@@ -70,6 +70,17 @@
# define ANKERL_UNORDERED_DENSE_NOINLINE __attribute__((noinline))
#endif
#if defined(__clang__) && defined(__has_attribute)
# if __has_attribute(__no_sanitize__)
# define ANKERL_UNORDERED_DENSE_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK \
__attribute__((__no_sanitize__("unsigned-integer-overflow")))
# endif
#endif
#if !defined(ANKERL_UNORDERED_DENSE_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK)
# define ANKERL_UNORDERED_DENSE_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
#endif
// defined in unordered_dense.cpp
#if !defined(ANKERL_UNORDERED_DENSE_EXPORT)
# define ANKERL_UNORDERED_DENSE_EXPORT
@@ -351,7 +362,8 @@ struct tuple_hash_helper {
}
}
[[nodiscard]] static auto mix64(uint64_t state, uint64_t v) -> uint64_t {
[[nodiscard]] ANKERL_UNORDERED_DENSE_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK static auto mix64(uint64_t state, uint64_t v)
-> uint64_t {
return detail::wyhash::mix(state + v, uint64_t{0x9ddfea08eb382d69});
}