Skip to content

[ASan][libc++] Optimize __annotate_delete for the default allocator #76176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions libcxx/include/deque
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,9 @@ private:

_LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT {
#ifndef _LIBCPP_HAS_NO_ASAN
// The default allocator does not require unpoisoning before returning memory.
if _LIBCPP_CONSTEXPR_SINCE_CXX17 (is_same<allocator_type, allocator<_Tp> >::value)
return;
if (empty()) {
for (size_t __i = 0; __i < __map_.size(); ++__i) {
__annotate_whole_block(__i, __asan_unposion);
Expand Down
6 changes: 4 additions & 2 deletions libcxx/include/string
Original file line number Diff line number Diff line change
Expand Up @@ -1912,8 +1912,10 @@ private:

_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_delete() const _NOEXCEPT {
#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
if (!__libcpp_is_constant_evaluated() && (__asan_short_string_is_annotated() || __is_long()))
__annotate_contiguous_container(data() + size() + 1, data() + capacity() + 1);
// The default allocator does not require unpoisoning before returning memory.
if _LIBCPP_CONSTEXPR_SINCE_CXX17 (!is_same<allocator_type, allocator<__default_allocator_type> >::value)
if (!__libcpp_is_constant_evaluated() && (__asan_short_string_is_annotated() || __is_long()))
__annotate_contiguous_container(data() + size() + 1, data() + capacity() + 1);
#endif
}

Expand Down
4 changes: 3 additions & 1 deletion libcxx/include/vector
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,9 @@ private:

_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT {
#ifndef _LIBCPP_HAS_NO_ASAN
__annotate_contiguous_container(data(), data() + capacity(), data() + size(), data() + capacity());
// The default allocator does not require unpoisoning before returning memory.
if _LIBCPP_CONSTEXPR_SINCE_CXX17 (!is_same<allocator_type, __default_allocator_type>::value)
__annotate_contiguous_container(data(), data() + capacity(), data() + size(), data() + capacity());
#endif
}

Expand Down