Skip to content

[libc++] Refactor vector's ASan annotations to only ever delete and add the annotations #152967

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

philnik777
Copy link
Contributor

This significantly simplifies the places where we insert/delete elements, since the code is exactly what you'd naively implement now. This also probably fixes some annotation issues when exceptions are thrown, since that will be handled correctly now through __scope_guard.

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions h -- libcxx/include/__vector/vector.h
View the diff from clang-format here.
diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index b9b8c654b..8d39a5047 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -830,7 +830,7 @@ template <class _Tp, class _Allocator>
 _LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) {
   __annotate_delete();
-  auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
+  auto __guard     = std::__make_scope_guard(__annotate_new_size(*this));
   auto __new_begin = __v.__begin_ - (__end_ - __begin_);
   std::__uninitialized_allocator_relocate(
       this->__alloc_, std::__to_address(__begin_), std::__to_address(__end_), std::__to_address(__new_begin));
@@ -850,7 +850,7 @@ template <class _Tp, class _Allocator>
 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer
 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) {
   __annotate_delete();
-  auto __guard = std::__make_scope_guard(__annotate_new_size(size()));
+  auto __guard  = std::__make_scope_guard(__annotate_new_size(size()));
   pointer __ret = __v.__begin_;
 
   // Relocate [__p, __end_) first to avoid having a hole in [__begin_, __end_)
@@ -935,7 +935,7 @@ template <class _InputIterator, class _Sentinel>
 _LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<_Tp, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
   auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
-  __end_ = std::__uninitialized_allocator_copy(this->__alloc_, std::move(__first), std::move(__last), __end_);
+  __end_       = std::__uninitialized_allocator_copy(this->__alloc_, std::move(__first), std::move(__last), __end_);
 }
 
 //  Default constructs __n objects starting at __end_
@@ -1174,7 +1174,7 @@ template <class _Tp, class _Allocator>
 _LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) {
   __annotate_delete();
-  auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
+  auto __guard        = std::__make_scope_guard(__annotate_new_size(*this));
   pointer __old_last  = this->__end_;
   difference_type __n = __old_last - __to;
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant