[llvm] [ADT] Remove xxHash64 ArrayRef/StringRef overloads. NFC (PR #196781)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat May 9 23:38:49 PDT 2026
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/196781
xxHash64 is a legacy, pre-XXH3 hash whose only non-test caller in the
monorepo is llvm::getKCFITypeID. #196774 accidentally exposed the API.
>From 0fcc09cf30d733379ed6ce305a167d97a6251bd9 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Sat, 9 May 2026 23:29:50 -0700
Subject: [PATCH] [ADT] Remove xxHash64 ArrayRef/StringRef overloads. NFC
xxHash64 is a legacy, pre-XXH3 hash whose only non-test caller in the
monorepo is llvm::getKCFITypeID. #196774 accidentally exposed the API.
---
llvm/include/llvm/ADT/ArrayRef.h | 3 ---
llvm/include/llvm/ADT/StringRef.h | 3 ---
llvm/lib/Support/Hash.cpp | 4 +++-
llvm/unittests/Support/xxhashTest.cpp | 12 ++++++++----
4 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index 366233fdefd02..cf2c6d85dc272 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -555,9 +555,6 @@ template <typename T> hash_code hash_value(ArrayRef<T> S) {
/// Inline ArrayRef overloads of the xxhash entry points declared
/// out-of-line in llvm/Support/xxhash.h. They live here so xxhash.h can stay
/// free of ADT dependencies.
-inline uint64_t xxHash64(ArrayRef<uint8_t> data) {
- return xxHash64(data.data(), data.size());
-}
inline uint64_t xxh3_64bits(ArrayRef<uint8_t> data) {
return xxh3_64bits(data.data(), data.size());
}
diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index 7ed0d6efdbeb3..5421224e6a1d3 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -944,9 +944,6 @@ inline std::string &operator+=(std::string &buffer, StringRef string) {
/// Inline StringRef overloads of the xxhash entry points declared out-of-line
/// in llvm/Support/xxhash.h. They live here so xxhash.h can stay free of ADT
/// dependencies.
-inline uint64_t xxHash64(StringRef data) {
- return xxHash64(reinterpret_cast<const uint8_t *>(data.data()), data.size());
-}
inline uint64_t xxh3_64bits(StringRef data) {
return xxh3_64bits(reinterpret_cast<const uint8_t *>(data.data()),
data.size());
diff --git a/llvm/lib/Support/Hash.cpp b/llvm/lib/Support/Hash.cpp
index d241a8a4cc753..6b5d000ee27c9 100644
--- a/llvm/lib/Support/Hash.cpp
+++ b/llvm/lib/Support/Hash.cpp
@@ -38,7 +38,9 @@ uint32_t llvm::getKCFITypeID(StringRef MangledTypeName,
switch (Algorithm) {
case KCFIHashAlgorithm::xxHash64:
// Use lower 32 bits of xxHash64
- return static_cast<uint32_t>(xxHash64(MangledTypeName));
+ return static_cast<uint32_t>(
+ xxHash64(reinterpret_cast<const uint8_t *>(MangledTypeName.data()),
+ MangledTypeName.size()));
case KCFIHashAlgorithm::FNV1a:
// FNV-1a hash (32-bit)
uint32_t Hash = 2166136261u; // FNV offset basis
diff --git a/llvm/unittests/Support/xxhashTest.cpp b/llvm/unittests/Support/xxhashTest.cpp
index 6764efe8e5415..9f91fc79e1f62 100644
--- a/llvm/unittests/Support/xxhashTest.cpp
+++ b/llvm/unittests/Support/xxhashTest.cpp
@@ -33,11 +33,15 @@ static void fillTestBuffer(uint8_t *buffer, size_t len) {
}
TEST(xxhashTest, Basic) {
- EXPECT_EQ(0xef46db3751d8e999U, xxHash64(StringRef()));
- EXPECT_EQ(0x33bf00a859c4ba3fU, xxHash64("foo"));
- EXPECT_EQ(0x48a37c90ad27a659U, xxHash64("bar"));
+ EXPECT_EQ(0xef46db3751d8e999U, xxHash64(nullptr, 0));
+ EXPECT_EQ(0x33bf00a859c4ba3fU,
+ xxHash64(reinterpret_cast<const uint8_t *>("foo"), 3));
+ EXPECT_EQ(0x48a37c90ad27a659U,
+ xxHash64(reinterpret_cast<const uint8_t *>("bar"), 3));
EXPECT_EQ(0x69196c1b3af0bff9U,
- xxHash64("0123456789abcdefghijklmnopqrstuvwxyz"));
+ xxHash64(reinterpret_cast<const uint8_t *>(
+ "0123456789abcdefghijklmnopqrstuvwxyz"),
+ 36));
}
TEST(xxhashTest, xxh3) {
More information about the llvm-commits
mailing list