Clang's unsigned integer overflow sanitizer is flagging BucketNumber as having an overflow. This seems to be intentional, and we should disable the sanitizer for this function.
PiperOrigin-RevId: 520968947
diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h
index 99369d3..1c4f0b9 100644
--- a/src/google/protobuf/map.h
+++ b/src/google/protobuf/map.h
@@ -1010,7 +1010,8 @@
}
template <typename K>
- size_type BucketNumber(const K& k) const {
+ size_type PROTOBUF_NO_SANITIZE("unsigned-integer-overflow")
+ BucketNumber(const K& k) const {
// We xor the hash value against the random seed so that we effectively
// have a random hash function.
uint64_t h = hash_function()(k) ^ seed_;
diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc
index 35aeae4..5805b47 100644
--- a/src/google/protobuf/port_def.inc
+++ b/src/google/protobuf/port_def.inc
@@ -879,6 +879,12 @@
#define PROTOBUF_UNUSED
#endif
+#if __has_attribute(no_sanitize)
+#define PROTOBUF_NO_SANITIZE(...) __attribute__((no_sanitize(__VA_ARGS__)))
+#else
+#define PROTOBUF_NO_SANITIZE(...)
+#endif
+
// ThreadSafeArenaz is turned off completely in opensource builds.
// autoheader defines this in some circumstances