Skip to content

Commit f04051d

Browse files
committed
libcxx: fix bogus integer sanitizer warnings in hash helpers
1 parent 03919ef commit f04051d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

libcxx/include/__config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,8 +1156,10 @@ typedef __char32_t char32_t;
11561156
// Allow for build-time disabling of unsigned integer sanitization
11571157
# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC)
11581158
# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
1159+
# define _LIBCPP_DISABLE_UBSAN_INTEGER_CHECK(reason) __attribute__((__no_sanitize__("integer")))
11591160
# else
11601161
# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1162+
# define _LIBCPP_DISABLE_UBSAN_INTEGER_CHECK(reason)
11611163
# endif
11621164

11631165
# if __has_feature(nullability)

libcxx/include/__functional/hash.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ struct __murmur2_or_cityhash<_Size, 64> {
132132
static const _Size __k2 = 0x9ae16a3b2f90404fULL;
133133
static const _Size __k3 = 0xc949d7c7509e6557ULL;
134134

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

139-
_LIBCPP_HIDE_FROM_ABI static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
140+
_LIBCPP_HIDE_FROM_ABI static _Size _LIBCPP_DISABLE_UBSAN_INTEGER_CHECK("shifting can cause unsigned overflow")
141+
__rotate_by_at_least_1(_Size __val, int __shift) {
140142
return (__val >> __shift) | (__val << (64 - __shift));
141143
}
142144

0 commit comments

Comments
 (0)