File indexing completed on 2026-05-03 08:13:26
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___LIBCXX_DEBUG_UTILS_SANITIZERS_H
0010 #define _LIBCPP___CXX03___LIBCXX_DEBUG_UTILS_SANITIZERS_H
0011
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__type_traits/integral_constant.h>
0014 #include <__cxx03/__type_traits/is_constant_evaluated.h>
0015
0016 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0017 # pragma GCC system_header
0018 #endif
0019
0020 #ifndef _LIBCPP_HAS_NO_ASAN
0021
0022 extern "C" {
0023 _LIBCPP_EXPORTED_FROM_ABI void
0024 __sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*);
0025 _LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container(
0026 const void*, const void*, const void*, const void*, const void*, const void*);
0027 _LIBCPP_EXPORTED_FROM_ABI int
0028 __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*);
0029 }
0030
0031 #endif
0032
0033 _LIBCPP_BEGIN_NAMESPACE_STD
0034
0035
0036 #ifndef _LIBCPP_HAS_NO_ASAN
0037 # define _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS 1
0038 #endif
0039
0040 #ifdef _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS
0041
0042
0043
0044 template <class _Alloc>
0045 struct __asan_annotate_container_with_allocator : true_type {};
0046 #endif
0047
0048
0049
0050
0051
0052 template <class _Allocator>
0053 _LIBCPP_HIDE_FROM_ABI void __annotate_double_ended_contiguous_container(
0054 const void* __first_storage,
0055 const void* __last_storage,
0056 const void* __first_old_contained,
0057 const void* __last_old_contained,
0058 const void* __first_new_contained,
0059 const void* __last_new_contained) {
0060 #ifdef _LIBCPP_HAS_NO_ASAN
0061 (void)__first_storage;
0062 (void)__last_storage;
0063 (void)__first_old_contained;
0064 (void)__last_old_contained;
0065 (void)__first_new_contained;
0066 (void)__last_new_contained;
0067 #else
0068 if (__asan_annotate_container_with_allocator<_Allocator>::value && __first_storage != nullptr)
0069 __sanitizer_annotate_double_ended_contiguous_container(
0070 __first_storage,
0071 __last_storage,
0072 __first_old_contained,
0073 __last_old_contained,
0074 __first_new_contained,
0075 __last_new_contained);
0076 #endif
0077 }
0078
0079
0080
0081
0082
0083 template <class _Allocator>
0084 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __annotate_contiguous_container(
0085 const void* __first_storage,
0086 const void* __last_storage,
0087 const void* __old_last_contained,
0088 const void* __new_last_contained) {
0089 #ifdef _LIBCPP_HAS_NO_ASAN
0090 (void)__first_storage;
0091 (void)__last_storage;
0092 (void)__old_last_contained;
0093 (void)__new_last_contained;
0094 #else
0095 if (!__libcpp_is_constant_evaluated() && __asan_annotate_container_with_allocator<_Allocator>::value &&
0096 __first_storage != nullptr)
0097 __sanitizer_annotate_contiguous_container(
0098 __first_storage, __last_storage, __old_last_contained, __new_last_contained);
0099 #endif
0100 }
0101
0102 _LIBCPP_END_NAMESPACE_STD
0103
0104 #endif