[libcxx-commits] [libcxx] [ASan][libc++] Update string ASan annotations to zero-overhead (PR #76165)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Dec 21 13:42:53 PST 2023
================
@@ -2075,27 +2095,43 @@ private:
// Assigns the value in __s, guaranteed to be __n < __min_cap in length.
inline _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_short(const value_type* __s, size_type __n) {
+#ifndef __LIBCPP_HAS_NO_ASAN
size_type __old_size = size();
- if (__n > __old_size)
- __annotate_increase(__n - __old_size);
+ _LIBCPP_IF_ASAN() {
+ if (__n > __old_size)
+ __annotate_increase(__n - __old_size);
+ }
+#endif
pointer __p =
__is_long() ? (__set_long_size(__n), __get_long_pointer()) : (__set_short_size(__n), __get_short_pointer());
traits_type::move(std::__to_address(__p), __s, __n);
traits_type::assign(__p[__n], value_type());
- if (__old_size > __n)
- __annotate_shrink(__old_size);
+#ifndef __LIBCPP_HAS_NO_ASAN
+ _LIBCPP_IF_ASAN() {
+ if (__old_size > __n)
+ __annotate_shrink(__old_size);
+ }
+#endif
return *this;
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
__null_terminate_at(value_type* __p, size_type __newsz) {
+#ifndef __LIBCPP_HAS_NO_ASAN
----------------
AdvenamTacet wrote:
We definitely should consider how to refactor it. I can reduce number of lines like that by removing a few not necessary variables, in another patch soon, but not completely remove all cases.
https://github.com/llvm/llvm-project/pull/76165
More information about the libcxx-commits
mailing list