Skip to content

[libc++] Fix bogus integer sanitizer warnings in hash helpers #146715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libcxx/include/__config
Original file line number Diff line number Diff line change
Expand Up @@ -1156,8 +1156,10 @@ typedef __char32_t char32_t;
// Allow for build-time disabling of unsigned integer sanitization
# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC)
# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
# define _LIBCPP_DISABLE_UBSAN_INTEGER_CHECK(reason) __attribute__((__no_sanitize__("integer")))
# else
# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
# define _LIBCPP_DISABLE_UBSAN_INTEGER_CHECK(reason)
# endif

# if __has_feature(nullability)
Expand Down
6 changes: 4 additions & 2 deletions libcxx/include/__functional/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ struct __murmur2_or_cityhash<_Size, 64> {
static const _Size __k2 = 0x9ae16a3b2f90404fULL;
static const _Size __k3 = 0xc949d7c7509e6557ULL;

_LIBCPP_HIDE_FROM_ABI static _Size __rotate(_Size __val, int __shift) {
_LIBCPP_HIDE_FROM_ABI static _Size _LIBCPP_DISABLE_UBSAN_INTEGER_CHECK("shifting can cause unsigned overflow")
__rotate(_Size __val, int __shift) {
return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
}

_LIBCPP_HIDE_FROM_ABI static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
_LIBCPP_HIDE_FROM_ABI static _Size _LIBCPP_DISABLE_UBSAN_INTEGER_CHECK("shifting can cause unsigned overflow")
__rotate_by_at_least_1(_Size __val, int __shift) {
return (__val >> __shift) | (__val << (64 - __shift));
}

Expand Down
Loading