[libcxx-commits] [libcxx] [libc++] Fix bogus integer sanitizer warnings in hash helpers (PR #146715)

Jean-Michaƫl Celerier via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 3 15:35:59 PDT 2025


https://github.com/jcelerier updated https://github.com/llvm/llvm-project/pull/146715

>From f04051d5ed0e80a5c8c911be131dbb8bb1b41c04 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?=
 <jeanmichael.celerier at gmail.com>
Date: Wed, 2 Jul 2025 11:00:01 -0400
Subject: [PATCH] libcxx: fix bogus integer sanitizer warnings in hash helpers

---
 libcxx/include/__config            | 2 ++
 libcxx/include/__functional/hash.h | 6 ++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__config b/libcxx/include/__config
index af8a297fdf3fd..2b15e53dcb3b7 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -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)
diff --git a/libcxx/include/__functional/hash.h b/libcxx/include/__functional/hash.h
index 489a6f00b8a3d..d5566bb7e3949 100644
--- a/libcxx/include/__functional/hash.h
+++ b/libcxx/include/__functional/hash.h
@@ -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));
   }
 



More information about the libcxx-commits mailing list