Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions libcxx/include/__memory/unique_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
_LIBCPP_PUSH_MACROS
#include <__undef_macros>

#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
extern "C" std::size_t __asan_load_cxx_array_cookie(std::size_t*);
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _Tp>
Expand Down Expand Up @@ -351,7 +355,12 @@ struct __unique_ptr_array_bounds_stateless {
// is in-bounds. The compiler catches invalid accesses anyway.
if (__libcpp_is_constant_evaluated())
return true;
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
// With ASan enabled, reading cookie directly causes errors because the memory is poisoned.
size_t __cookie = __asan_load_cxx_array_cookie(reinterpret_cast<size_t*>(__ptr) - 1);
#else
size_t __cookie = std::__get_array_cookie(__ptr);
#endif
return __index < __cookie;
}

Expand Down Expand Up @@ -379,7 +388,12 @@ struct __unique_ptr_array_bounds_stored {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Tp* __ptr, size_t __index) const {
if (__libcpp_is_constant_evaluated())
return true;
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
// With ASan enabled, reading cookie directly causes errors because the memory is poisoned.
size_t __cookie = __asan_load_cxx_array_cookie(reinterpret_cast<size_t*>(__ptr) - 1);
#else
size_t __cookie = std::__get_array_cookie(__ptr);
#endif
return __index < __cookie;
}

Expand Down