[libcxx-commits] [libcxx] WIP: [libc++][asan] Suppress SSO with _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS_FOR_STRING (PR #195740)
Vitaly Buka via libcxx-commits
libcxx-commits at lists.llvm.org
Mon May 4 13:54:25 PDT 2026
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/195740
None
>From 3723463fb4791f2a071051eac08fd415e494d24e Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Mon, 4 May 2026 13:54:10 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.7
---
libcxx/include/string | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/libcxx/include/string b/libcxx/include/string
index 002ce63ce5af9..c4b2eaef5806d 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -2288,12 +2288,18 @@ private:
if (__size > max_size())
__throw_length_error();
- if (__fits_in_sso(__size)) {
+ size_type __min_cap_val = __size;
+# if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS_FOR_STRING
+ if (!__libcpp_is_constant_evaluated())
+ __min_cap_val = std::max(__min_cap_val, size_type(32));
+# endif
+
+ if (__fits_in_sso(__min_cap_val)) {
__set_short_size(__size);
__annotate_new(__size);
return __get_short_pointer();
} else {
- __rep_.__l = __allocate_long_buffer(__alloc_, __size);
+ __rep_.__l = __allocate_long_buffer(__alloc_, __size, __min_cap_val);
__annotate_new(__size);
return __get_long_pointer();
}
@@ -2327,7 +2333,11 @@ private:
# endif
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_new(size_type __current_size) const _NOEXCEPT {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_new(size_type __current_size) _NOEXCEPT {
+# if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS_FOR_STRING
+ if (__libcpp_is_constant_evaluated() && !__is_long())
+ __rep_.__l = __allocate_long_buffer(__alloc_, __current_size, 32);
+# endif
__annotate_contiguous_container(data() + capacity() + 1, data() + __current_size + 1);
}
More information about the libcxx-commits
mailing list