Skip to content

Commit e267ef9

Browse files
committed
[libc++] Instantiate hash function externally
1 parent 59cbe2f commit e267ef9

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

libcxx/include/__configuration/availability.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
// in all versions of the library are available.
7979
#if !_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS
8080

81+
# define _LIBCPP_INTRODUCED_IN_LLVM_21 1
82+
# define _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE /* nothing */
83+
8184
# define _LIBCPP_INTRODUCED_IN_LLVM_20 1
8285
# define _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE /* nothing */
8386

@@ -114,6 +117,11 @@
114117

115118
// clang-format off
116119

120+
// LLVM 21
121+
// TODO: Fill this in
122+
# define _LIBCPP_INTRODUCED_IN_LLVM_21 0
123+
# define _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE __attribute__((unavailable))
124+
117125
// LLVM 20
118126
// TODO: Fill this in
119127
# define _LIBCPP_INTRODUCED_IN_LLVM_20 0
@@ -359,6 +367,9 @@
359367
#define _LIBCPP_AVAILABILITY_HAS_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20
360368
#define _LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE
361369

370+
#define _LIBCPP_AVAILABILITY_HAS_HASH _LIBCPP_INTRODUCED_IN_LLVM_21
371+
// No attribute, since we've had hash in the headers before
372+
362373
// Define availability attributes that depend on _LIBCPP_HAS_EXCEPTIONS.
363374
// Those are defined in terms of the availability attributes above, and
364375
// should not be vendor-specific.

libcxx/include/__functional/hash.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ struct __murmur2_or_cityhash<_Size, 64> {
237237
}
238238
};
239239

240+
#if _LIBCPP_AVAILABILITY_HAS_HASH
241+
[[__gnu__::__pure__]] _LIBCPP_EXPORTED_FROM_ABI size_t __hash_memory(_LIBCPP_NOESCAPE const void*, size_t) _NOEXCEPT;
242+
#else
243+
_LIBCPP_HIDE_FROM_ABI inline size_t __hash_memory(const void* __ptr, size_t __size) {
244+
return __murmur2_or_cityhash<size_t>()(__ptr, __size);
245+
}
246+
#endif
247+
240248
template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
241249
struct __scalar_hash;
242250

@@ -276,7 +284,7 @@ struct __scalar_hash<_Tp, 2> : public __unary_function<_Tp, size_t> {
276284
} __s;
277285
} __u;
278286
__u.__t = __v;
279-
return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
287+
return std::__hash_memory(&__u, sizeof(__u));
280288
}
281289
};
282290

@@ -292,7 +300,7 @@ struct __scalar_hash<_Tp, 3> : public __unary_function<_Tp, size_t> {
292300
} __s;
293301
} __u;
294302
__u.__t = __v;
295-
return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
303+
return std::__hash_memory(&__u, sizeof(__u));
296304
}
297305
};
298306

@@ -309,7 +317,7 @@ struct __scalar_hash<_Tp, 4> : public __unary_function<_Tp, size_t> {
309317
} __s;
310318
} __u;
311319
__u.__t = __v;
312-
return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
320+
return std::__hash_memory(&__u, sizeof(__u));
313321
}
314322
};
315323

@@ -332,7 +340,7 @@ struct _LIBCPP_TEMPLATE_VIS hash<_Tp*> : public __unary_function<_Tp*, size_t> {
332340
size_t __a;
333341
} __u;
334342
__u.__t = __v;
335-
return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
343+
return std::__hash_memory(&__u, sizeof(__u));
336344
}
337345
};
338346

libcxx/include/__string/char_traits.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ __str_find_last_not_of(const _CharT* __p, _SizeT __sz, _CharT __c, _SizeT __pos)
534534
template <class _Ptr>
535535
inline _LIBCPP_HIDE_FROM_ABI size_t __do_string_hash(_Ptr __p, _Ptr __e) {
536536
typedef typename iterator_traits<_Ptr>::value_type value_type;
537-
return __murmur2_or_cityhash<size_t>()(__p, (__e - __p) * sizeof(value_type));
537+
return std::__hash_memory(__p, (__e - __p) * sizeof(value_type));
538538
}
539539

540540
_LIBCPP_END_NAMESPACE_STD

libcxx/src/functional.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ bad_function_call::~bad_function_call() noexcept {}
1616
const char* bad_function_call::what() const noexcept { return "std::bad_function_call"; }
1717
#endif
1818

19+
size_t __hash_memory(_LIBCPP_NOESCAPE const void* ptr, size_t size) _NOEXCEPT {
20+
return __murmur2_or_cityhash<size_t>()(ptr, size);
21+
}
22+
1923
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)