Skip to content
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

[ASan][libc++][NFC] refactor vector annotations arguments #78322

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

AdvenamTacet
Copy link
Member

This commit simplifies ASan helper functions in std::vector by removing arguments which can be calculated later.

Short term it improves readability of helper functions in std::vector.

Long term it aims to help with a bigger refactor of container annotations.

This commit simplifies ASan helper functions in `std::vector` by removing arguments which can be calculated later.

Short term it improves readability of helper functions in `std::vector`.

Long term it aims to help with a bigger refactor of container annotations.
@AdvenamTacet AdvenamTacet added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 16, 2024
@AdvenamTacet AdvenamTacet requested a review from a team as a code owner January 16, 2024 18:38
@llvmbot
Copy link
Member

llvmbot commented Jan 16, 2024

@llvm/pr-subscribers-libcxx

Author: Tacet (AdvenamTacet)

Changes

This commit simplifies ASan helper functions in std::vector by removing arguments which can be calculated later.

Short term it improves readability of helper functions in std::vector.

Long term it aims to help with a bigger refactor of container annotations.


Full diff: https://github.com/llvm/llvm-project/pull/78322.diff

1 Files Affected:

  • (modified) libcxx/include/vector (+7-7)
diff --git a/libcxx/include/vector b/libcxx/include/vector
index 0098273a195ff8..e9dd57055cb112 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -832,12 +832,12 @@ private:
   // the documentation for __sanitizer_annotate_contiguous_container.
 
   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_contiguous_container(
-      const void* __beg, const void* __end, const void* __old_mid, const void* __new_mid) const {
-    (void)__beg;
-    (void)__end;
+      const void* __old_mid, const void* __new_mid) const {
     (void)__old_mid;
     (void)__new_mid;
 #ifndef _LIBCPP_HAS_NO_ASAN
+    const void* __beg = data();
+    const void* __end = data() + capacity();
     if (!__libcpp_is_constant_evaluated() && __beg != nullptr &&
         __asan_annotate_container_with_allocator<_Allocator>::value)
       __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
@@ -847,27 +847,27 @@ private:
   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_new(size_type __current_size) const _NOEXCEPT {
     (void)__current_size;
 #ifndef _LIBCPP_HAS_NO_ASAN
-    __annotate_contiguous_container(data(), data() + capacity(), data() + capacity(), data() + __current_size);
+    __annotate_contiguous_container(data() + capacity(), data() + __current_size);
 #endif
   }
 
   _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());
+    __annotate_contiguous_container(data() + size(), data() + capacity());
 #endif
   }
 
   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_increase(size_type __n) const _NOEXCEPT {
     (void)__n;
 #ifndef _LIBCPP_HAS_NO_ASAN
-    __annotate_contiguous_container(data(), data() + capacity(), data() + size(), data() + size() + __n);
+    __annotate_contiguous_container(data() + size(), data() + size() + __n);
 #endif
   }
 
   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_shrink(size_type __old_size) const _NOEXCEPT {
     (void)__old_size;
 #ifndef _LIBCPP_HAS_NO_ASAN
-    __annotate_contiguous_container(data(), data() + capacity(), data() + __old_size, data() + size());
+    __annotate_contiguous_container(data() + __old_size, data() + size());
 #endif
   }
 

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM assuming the CI is green.

@AdvenamTacet AdvenamTacet merged commit 2b3cdd6 into llvm:main Jan 17, 2024
44 checks passed
@AdvenamTacet AdvenamTacet deleted the vector-arguments-refactor branch January 17, 2024 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants