[libcxx-commits] [libcxx] [ASan][libc++] std::basic_string annotations (PR #72677)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Nov 22 16:22:21 PST 2023
https://github.com/AdvenamTacet updated https://github.com/llvm/llvm-project/pull/72677
>From 3ffdc6b5e2ae6a073ce65c0c0f4f7bb37e062f0b Mon Sep 17 00:00:00 2001
From: Advenam Tacet <advenam.tacet at trailofbits.com>
Date: Fri, 17 Nov 2023 01:51:21 +0100
Subject: [PATCH 1/3] [ASan][libc++] std::basic_string annotations
This commit turns on basic annotations for std::basic_string, similar to those in std::vector and std::deque.
Originally proposed here: https://reviews.llvm.org/D132769
Related patches:
Turning on annotations for short strings: https://reviews.llvm.org/D147680
Turning on annotations for all allocators: https://reviews.llvm.org/D146214
This revision is a part of a series of patches extending AddressSanitizer C++ container overflow detection capabilities by adding annotations, similar to those existing in std::vector, to std::string and std::deque collections. These changes allow ASan to detect cases when the instrumented program accesses memory which is internally allocated by the collection but is still not in-use (accesses before or after the stored elements for std::deque, or between the size and capacity bounds for std::string).
The motivation for the research and those changes was a bug, found by Trail of Bits, in a real code where an out-of-bounds read could happen as two strings were compared via a std::equals function that took iter1_begin, iter1_end, iter2_begin iterators (with a custom comparison function). When object iter1 was longer than iter2, read out-of-bounds on iter2 could happen. Container sanitization would detect it.
This Pull Request adds annotations for `std::basic_string`. Long string is very similar to std::vector, and therefore works well with `__sanitizer_annotate_contiguous_container` from LLVM 15 and therefore annotations works if that implementation is compiled with previous LLVM.
However, only the standard allocator is supported.
As D132522 extended possibilities of `__sanitizer_annotate_contiguous_container`, now annotations may be supported with all allocators, but that support will be added in a next PR. Only strings with default allocator are annotated with that commit.
If you have any questions, please email:
- advenam.tacet at trailofbits.com
- disconnect3d at trailofbits.com
---
libcxx/include/string | 282 ++++++++++++++----
.../string.capacity/capacity.pass.cpp | 1 +
.../string.capacity/clear.pass.cpp | 7 +
.../string.capacity/reserve.pass.cpp | 3 +
.../reserve_size.asan.pass.cpp | 81 +++++
.../string.capacity/reserve_size.pass.cpp | 1 +
.../resize_and_overwrite.pass.cpp | 4 +
.../string.capacity/resize_size.pass.cpp | 15 +-
.../string.capacity/resize_size_char.pass.cpp | 24 +-
.../string.capacity/shrink_to_fit.pass.cpp | 8 +
.../string.cons/T_size_size.pass.cpp | 30 +-
.../basic.string/string.cons/alloc.pass.cpp | 30 +-
.../string.cons/brace_assignment.pass.cpp | 3 +
.../string.cons/char_assignment.pass.cpp | 2 +
.../basic.string/string.cons/copy.pass.cpp | 4 +
.../string.cons/copy_alloc.pass.cpp | 3 +
.../string.cons/copy_assignment.pass.cpp | 3 +
.../basic.string/string.cons/default.pass.cpp | 2 +
.../string.cons/initializer_list.pass.cpp | 9 +
.../initializer_list_assignment.pass.cpp | 11 +-
.../string.cons/iter_alloc.pass.cpp | 3 +
.../string.cons/iter_alloc_deduction.pass.cpp | 1 +
.../basic.string/string.cons/move.pass.cpp | 4 +
.../string.cons/move_alloc.pass.cpp | 4 +
.../string.cons/move_assignment.pass.cpp | 5 +
.../string.cons/pointer_alloc.pass.cpp | 3 +
.../string.cons/pointer_assignment.pass.cpp | 3 +
.../string.cons/pointer_size_alloc.pass.cpp | 3 +
.../string.cons/size_char_alloc.pass.cpp | 3 +
.../string.cons/string_view.pass.cpp | 5 +
.../string_view_assignment.pass.cpp | 3 +
.../basic.string/string.cons/substr.pass.cpp | 62 ++--
.../string_append/initializer_list.pass.cpp | 4 +-
.../string_append/iterator.pass.cpp | 2 +
.../string_append/pointer.pass.cpp | 2 +
.../string_append/pointer_size.pass.cpp | 2 +
.../string_append/push_back.pass.cpp | 2 +
.../string_append/size_char.pass.cpp | 2 +
.../string_append/string.pass.cpp | 2 +
.../string_append/string_size_size.pass.cpp | 14 +-
.../string_assign/T_size_size.pass.cpp | 14 +-
.../string_assign/initializer_list.pass.cpp | 3 +
.../string_assign/iterator.pass.cpp | 2 +
.../string_assign/pointer.pass.cpp | 2 +
.../string_assign/pointer_size.pass.cpp | 2 +
.../string_assign/size_char.pass.cpp | 2 +
.../string_assign/string.pass.cpp | 3 +
.../string_assign/string_size_size.pass.cpp | 14 +-
.../string_copy/copy.pass.cpp | 10 +-
.../string_erase/iter.pass.cpp | 2 +
.../string_erase/iter_iter.pass.cpp | 2 +
.../string_erase/pop_back.asan.pass.cpp | 65 ++++
.../string_erase/pop_back.pass.cpp | 3 +
.../string_erase/size_size.pass.cpp | 20 +-
.../string_insert/iter_char.pass.cpp | 22 +-
.../iter_initializer_list.pass.cpp | 2 +
.../string_insert/iter_iter_iter.pass.cpp | 2 +
.../string_insert/iter_size_char.pass.cpp | 2 +
.../string_insert/size_pointer.pass.cpp | 18 +-
.../string_insert/size_pointer_size.pass.cpp | 18 +-
.../string_insert/size_size_char.pass.cpp | 18 +-
.../string_insert/size_string.pass.cpp | 18 +-
.../size_string_size_size.pass.cpp | 18 +-
.../string_op_plus_equal/char.pass.cpp | 2 +
.../initializer_list.pass.cpp | 2 +
.../string_op_plus_equal/pointer.pass.cpp | 2 +
.../string_op_plus_equal/string.pass.cpp | 2 +
.../string_replace/iter_iter_string.pass.cpp | 3 +
.../size_size_T_size_size.pass.cpp | 17 +-
.../string_replace/size_size_pointer.pass.cpp | 25 +-
.../size_size_pointer_size.pass.cpp | 25 +-
.../size_size_size_char.pass.cpp | 24 +-
.../string_replace/size_size_string.pass.cpp | 24 +-
.../size_size_string_size_size.pass.cpp | 24 +-
.../size_size_string_view.pass.cpp | 24 +-
.../string_swap/swap.asan.pass.cpp | 102 +++++++
.../string_swap/swap.pass.cpp | 3 +
.../string.special/swap.pass.cpp | 3 +
.../string_op+/char_string.pass.cpp | 2 +
.../string_op+/string_char.pass.cpp | 2 +
.../string_op+/string_pointer.pass.cpp | 2 +
.../string_op+/string_string.pass.cpp | 2 +
libcxx/test/support/asan_testing.h | 62 +++-
83 files changed, 995 insertions(+), 271 deletions(-)
create mode 100644 libcxx/test/std/strings/basic.string/string.capacity/reserve_size.asan.pass.cpp
create mode 100644 libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.asan.pass.cpp
create mode 100644 libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.asan.pass.cpp
diff --git a/libcxx/include/string b/libcxx/include/string
index 9c2efac8006bd72..9362b1bcd16fa19 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -645,6 +645,16 @@ basic_string<char32_t> operator""s( const char32_t *str, size_t len );
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
+#ifndef _LIBCPP_HAS_NO_ASAN
+# define _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS __attribute__((__no_sanitize__("address")))
+// Sometimes string access own memory, which should not be accessed by different parts of program
+// (eg. not-in-use bytes of buffer in short string) and are poisoned by ASan.
+// This macro turns off instrumentation in a function, so memory accesses which normally would crash
+// work as expected.
+#else
+# define _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
+#endif
+#define _LIBCPP_SHORT_STRING_ANNOTATIONS_ALLOWED false
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -702,6 +712,9 @@ struct __init_with_sentinel_tag {};
template<class _CharT, class _Traits, class _Allocator>
class basic_string
{
+private:
+ using __default_allocator_type = allocator<_CharT>;
+
public:
typedef basic_string __self;
typedef basic_string_view<_CharT, _Traits> __self_view;
@@ -888,34 +901,46 @@ public:
#endif
: __r_(__value_init_tag(), __a) {}
- _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str)
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS basic_string(const basic_string& __str)
: __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) {
if (!__str.__is_long())
+ {
__r_.first() = __str.__r_.first();
+ __annotate_new(__get_short_size());
+ }
else
__init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
}
- _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str, const allocator_type& __a)
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS basic_string(const basic_string& __str, const allocator_type& __a)
: __r_(__default_init_tag(), __a) {
if (!__str.__is_long())
+ {
__r_.first() = __str.__r_.first();
+ __annotate_new(__get_short_size());
+ }
else
__init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
}
#ifndef _LIBCPP_CXX03_LANG
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
+ basic_string(basic_string&& __str)
# if _LIBCPP_STD_VER <= 14
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
# else
_NOEXCEPT
# endif
- : __r_(std::move(__str.__r_)) {
+ // Turning off ASan instrumentation for variable initialization with _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
+ // is inconsistent and that initialization may be annotated.
+ // Therefore, to copy __str memory, we have to unpoison it first (if object is poisoned and not external buffer,
+ // so short string case).
+ : __r_( ( (__str.__is_long() ? 0 : (__str.__annotate_delete(), 0)), std::move(__str.__r_)) ) {
__str.__r_.first() = __rep();
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str, const allocator_type& __a)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
+ basic_string(basic_string&& __str, const allocator_type& __a)
: __r_(__default_init_tag(), __a) {
if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
__init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
@@ -923,6 +948,9 @@ public:
if (__libcpp_is_constant_evaluated())
__r_.first() = __rep();
__r_.first() = __str.__r_.first();
+ if (!__str.__is_long()) {
+ __str.__annotate_delete();
+ }
__str.__r_.first() = __rep();
}
}
@@ -965,11 +993,11 @@ public:
}
#if _LIBCPP_STD_VER >= 23
- _LIBCPP_HIDE_FROM_ABI constexpr
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS constexpr
basic_string(basic_string&& __str, size_type __pos, const _Allocator& __alloc = _Allocator())
: basic_string(std::move(__str), __pos, npos, __alloc) {}
- _LIBCPP_HIDE_FROM_ABI constexpr
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS constexpr
basic_string(basic_string&& __str, size_type __pos, size_type __n, const _Allocator& __alloc = _Allocator())
: __r_(__default_init_tag(), __alloc) {
if (__pos > __str.size())
@@ -1081,6 +1109,7 @@ public:
#endif // _LIBCPP_CXX03_LANG
inline _LIBCPP_CONSTEXPR_SINCE_CXX20 ~basic_string() {
+ __annotate_delete();
if (__is_long())
__alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
}
@@ -1098,8 +1127,8 @@ public:
}
#ifndef _LIBCPP_CXX03_LANG
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(basic_string&& __str)
- _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS basic_string&
+ operator=(basic_string&& __str) _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) {
__move_assign(__str, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
return *this;
}
@@ -1112,7 +1141,7 @@ public:
#if _LIBCPP_STD_VER >= 23
basic_string& operator=(nullptr_t) = delete;
#endif
- _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(value_type __c);
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS basic_string& operator=(value_type __c);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
iterator begin() _NOEXCEPT
@@ -1329,7 +1358,7 @@ public:
}
#if _LIBCPP_STD_VER >= 20
- _LIBCPP_HIDE_FROM_ABI constexpr
+ _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
void __move_assign(basic_string&& __str, size_type __pos, size_type __len) {
// Pilfer the allocation from __str.
_LIBCPP_ASSERT_INTERNAL(__alloc() == __str.__alloc(), "__move_assign called with wrong allocator");
@@ -1345,7 +1374,7 @@ public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
basic_string& assign(const basic_string& __str) { return *this = __str; }
#ifndef _LIBCPP_CXX03_LANG
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
basic_string& assign(basic_string&& __str)
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
{*this = std::move(__str); return *this;}
@@ -1736,7 +1765,7 @@ private:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __shrink_or_extend(size_type __target_capacity);
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
bool __is_long() const _NOEXCEPT {
if (__libcpp_is_constant_evaluated() && __builtin_constant_p(__r_.first().__l.__is_long_)) {
return __r_.first().__l.__is_long_;
@@ -1776,6 +1805,7 @@ private:
value_type* __p;
if (__cap - __sz >= __n)
{
+ __annotate_increase(__n);
__p = std::__to_address(__get_pointer());
size_type __n_move = __sz - __ip;
if (__n_move != 0)
@@ -1802,7 +1832,7 @@ private:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 allocator_type& __alloc() _NOEXCEPT { return __r_.second(); }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const allocator_type& __alloc() const _NOEXCEPT { return __r_.second(); }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
void __set_short_size(size_type __s) _NOEXCEPT {
_LIBCPP_ASSERT_INTERNAL(
__s < __min_cap, "__s should never be greater than or equal to the short string capacity");
@@ -1810,7 +1840,7 @@ private:
__r_.first().__s.__is_long_ = false;
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
size_type __get_short_size() const _NOEXCEPT {
_LIBCPP_ASSERT_INTERNAL(
!__r_.first().__s.__is_long_, "String has to be short when trying to get the short size");
@@ -1860,6 +1890,45 @@ private:
const_pointer __get_pointer() const _NOEXCEPT
{return __is_long() ? __get_long_pointer() : __get_short_pointer();}
+ // The following functions are no-ops outside of AddressSanitizer mode.
+#ifndef _LIBCPP_HAS_NO_ASAN
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_contiguous_container(
+ const void* __old_mid, const void* __new_mid) const {
+ const void* __begin = data();
+ const void* __end = data() + capacity() + 1;
+ if (!__libcpp_is_constant_evaluated() && __begin != nullptr && is_same<allocator_type, __default_allocator_type>::value)
+ __sanitizer_annotate_contiguous_container(__begin, __end, __old_mid, __new_mid);
+ }
+#else
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+ __annotate_contiguous_container(const void*, const void*) const {}
+#endif
+
+ // ASan: short string is poisoned if and only if this function returns true.
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __asan_short_string_is_annotated() const _NOEXCEPT {
+ return _LIBCPP_SHORT_STRING_ANNOTATIONS_ALLOWED && !__libcpp_is_constant_evaluated();
+ }
+
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_new(size_type __current_size) const _NOEXCEPT {
+ if (!__libcpp_is_constant_evaluated() && (__asan_short_string_is_annotated() || __is_long()))
+ __annotate_contiguous_container(data() + capacity() + 1, data() + __current_size + 1);
+ }
+
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_delete() const _NOEXCEPT {
+ if (!__libcpp_is_constant_evaluated() && (__asan_short_string_is_annotated() || __is_long()))
+ __annotate_contiguous_container(data() + size() + 1, data() + capacity() + 1);
+ }
+
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_increase(size_type __n) const _NOEXCEPT {
+ if (!__libcpp_is_constant_evaluated() && (__asan_short_string_is_annotated() || __is_long()))
+ __annotate_contiguous_container(data() + size() + 1, data() + size() + 1 + __n);
+ }
+
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_shrink(size_type __old_size) const _NOEXCEPT {
+ if (!__libcpp_is_constant_evaluated() && (__asan_short_string_is_annotated() || __is_long()))
+ __annotate_contiguous_container(data() + __old_size + 1, data() + size() + 1);
+ }
+
template <size_type __a> static
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
size_type __align_it(size_type __s) _NOEXCEPT
@@ -1962,6 +2031,7 @@ private:
}
else
{
+ __annotate_delete();
allocator_type __a = __str.__alloc();
auto __allocation = std::__allocate_at_least(__a, __str.__get_long_cap());
__begin_lifetime(__allocation.ptr, __allocation.count);
@@ -1971,6 +2041,7 @@ private:
__set_long_pointer(__allocation.ptr);
__set_long_cap(__allocation.count);
__set_long_size(__str.size());
+ __annotate_new(__get_long_size());
}
}
}
@@ -2018,18 +2089,28 @@ 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) {
+ size_type __old_size = size();
+ if (__n > __old_size)
+ __annotate_increase(__n - __old_size);
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);
return *this;
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
basic_string& __null_terminate_at(value_type* __p, size_type __newsz) {
+ size_type __old_size = size();
+ if (__newsz > __old_size)
+ __annotate_increase(__newsz - __old_size);
__set_size(__newsz);
traits_type::assign(__p[__newsz], value_type());
+ if (__old_size > __newsz)
+ __annotate_shrink(__old_size);
return *this;
}
@@ -2136,6 +2217,7 @@ void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
}
traits_type::copy(std::__to_address(__p), __s, __sz);
traits_type::assign(__p[__sz], value_type());
+ __annotate_new(__sz);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2164,6 +2246,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_ty
}
traits_type::copy(std::__to_address(__p), __s, __sz);
traits_type::assign(__p[__sz], value_type());
+ __annotate_new(__sz);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2188,6 +2271,7 @@ void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
__set_long_size(__sz);
}
traits_type::copy(std::__to_address(__p), __s, __sz + 1);
+ __annotate_new(__sz);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2217,6 +2301,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
}
traits_type::assign(std::__to_address(__p), __n, __c);
traits_type::assign(__p[__n], value_type());
+ __annotate_new(__n);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2243,6 +2328,7 @@ void basic_string<_CharT, _Traits, _Allocator>::__init_with_sentinel(_InputItera
}
catch (...)
{
+ __annotate_delete();
if (__is_long())
__alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
throw;
@@ -2298,11 +2384,13 @@ void basic_string<_CharT, _Traits, _Allocator>::__init_with_size(
}
catch (...)
{
+ __annotate_delete();
if (__is_long())
__alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
throw;
}
#endif // _LIBCPP_HAS_NO_EXCEPTIONS
+ __annotate_new(__sz);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2319,6 +2407,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
size_type __cap = __old_cap < __ms / 2 - __alignment ?
__recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) :
__ms - 1;
+ __annotate_delete();
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
pointer __p = __allocation.ptr;
__begin_lifetime(__p, __allocation.count);
@@ -2338,6 +2427,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
__old_sz = __n_copy + __n_add + __sec_cp_sz;
__set_long_size(__old_sz);
traits_type::assign(__p[__old_sz], value_type());
+ __annotate_new(__old_cap + __delta_cap);
}
// __grow_by is deprecated because it does not set the size. It may not update the size when the size is changed, and it
@@ -2360,6 +2450,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_t
size_type __cap = __old_cap < __ms / 2 - __alignment ?
__recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) :
__ms - 1;
+ __annotate_delete();
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
pointer __p = __allocation.ptr;
__begin_lifetime(__p, __allocation.count);
@@ -2402,10 +2493,15 @@ basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(
const value_type* __s, size_type __n) {
size_type __cap = __is_short ? static_cast<size_type>(__min_cap) : __get_long_cap();
if (__n < __cap) {
+ size_type __old_size = __is_short ? __get_short_size() : __get_long_size();
+ if (__n > __old_size)
+ __annotate_increase(__n - __old_size);
pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
__is_short ? __set_short_size(__n) : __set_long_size(__n);
traits_type::copy(std::__to_address(__p), __s, __n);
traits_type::assign(__p[__n], value_type());
+ if (__old_size > __n)
+ __annotate_shrink(__old_size);
} else {
size_type __sz = __is_short ? __get_short_size() : __get_long_size();
__grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s);
@@ -2420,6 +2516,9 @@ basic_string<_CharT, _Traits, _Allocator>::__assign_external(
const value_type* __s, size_type __n) {
size_type __cap = capacity();
if (__cap >= __n) {
+ size_type __old_size = size();
+ if (__n > __old_size)
+ __annotate_increase(__n - __old_size);
value_type* __p = std::__to_address(__get_pointer());
traits_type::move(__p, __s, __n);
return __null_terminate_at(__p, __n);
@@ -2447,11 +2546,15 @@ basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
{
size_type __cap = capacity();
+ size_type __old_size = size();
if (__cap < __n)
{
size_type __sz = size();
__grow_by_without_replace(__cap, __n - __cap, __sz, 0, __sz);
+ __annotate_increase(__n);
}
+ else if(__n > __old_size)
+ __annotate_increase(__n - __old_size);
value_type* __p = std::__to_address(__get_pointer());
traits_type::assign(__p, __n, __c);
return __null_terminate_at(__p, __n);
@@ -2462,24 +2565,26 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
{
- pointer __p;
- if (__is_long())
- {
- __p = __get_long_pointer();
- __set_long_size(1);
- }
- else
- {
- __p = __get_short_pointer();
- __set_short_size(1);
- }
- traits_type::assign(*__p, __c);
- traits_type::assign(*++__p, value_type());
- return *this;
+ pointer __p;
+ size_type __old_size = size();
+ if (__old_size == 0)
+ __annotate_increase(1);
+ if (__is_long()) {
+ __p = __get_long_pointer();
+ __set_long_size(1);
+ } else {
+ __p = __get_short_pointer();
+ __set_short_size(1);
+ }
+ traits_type::assign(*__p, __c);
+ traits_type::assign(*++__p, value_type());
+ if (__old_size > 1)
+ __annotate_shrink(__old_size);
+ return *this;
}
template <class _CharT, class _Traits, class _Allocator>
-_LIBCPP_CONSTEXPR_SINCE_CXX20
+_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
{
@@ -2487,7 +2592,12 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
__copy_assign_alloc(__str);
if (!__is_long()) {
if (!__str.__is_long()) {
+ size_type __old_size = __get_short_size();
+ if (__get_short_size() < __str.__get_short_size())
+ __annotate_increase(__str.__get_short_size() - __get_short_size());
__r_.first() = __str.__r_.first();
+ if (__old_size > __get_short_size())
+ __annotate_shrink(__old_size);
} else {
return __assign_no_alias<true>(__str.data(), __str.size());
}
@@ -2513,7 +2623,7 @@ basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, fa
}
template <class _CharT, class _Traits, class _Allocator>
-inline _LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
void
basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
#if _LIBCPP_STD_VER >= 17
@@ -2522,20 +2632,42 @@ basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, tr
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
#endif
{
+ __annotate_delete();
if (__is_long()) {
- __alloc_traits::deallocate(__alloc(), __get_long_pointer(),
- __get_long_cap());
+ __alloc_traits::deallocate(__alloc(), __get_long_pointer(),
+ __get_long_cap());
#if _LIBCPP_STD_VER <= 14
- if (!is_nothrow_move_assignable<allocator_type>::value) {
+ if (!is_nothrow_move_assignable<allocator_type>::value) {
__set_short_size(0);
traits_type::assign(__get_short_pointer()[0], value_type());
- }
+ }
#endif
}
+ size_type __str_old_size = __str.size();
+ bool __str_was_short = !__str.__is_long();
+
__move_assign_alloc(__str);
__r_.first() = __str.__r_.first();
__str.__set_short_size(0);
traits_type::assign(__str.__get_short_pointer()[0], value_type());
+
+ if (__str_was_short && this != &__str)
+ __str.__annotate_shrink(__str_old_size);
+ else
+ // ASan annotations: was long, so object memory is unpoisoned as new.
+ // Or is same as *this, and __annotate_delete() was called.
+ __str.__annotate_new(0);
+
+ // ASan annotations: Guard against `std::string s; s = std::move(s);`
+ // You can find more here: https://en.cppreference.com/w/cpp/utility/move
+ // Quote: "Unless otherwise specified, all standard library objects that have been moved
+ // from are placed in a "valid but unspecified state", meaning the object's class
+ // invariants hold (so functions without preconditions, such as the assignment operator,
+ // can be safely used on the object after it was moved from):"
+ // Quote: "v = std::move(v); // the value of v is unspecified"
+ if (!__is_long() && &__str != this)
+ // If it is long string, delete was never called.
+ __annotate_new(__get_short_size());
}
#endif
@@ -2580,7 +2712,7 @@ void
basic_string<_CharT, _Traits, _Allocator>::__assign_trivial(_Iterator __first, _Sentinel __last, size_type __n) {
_LIBCPP_ASSERT_INTERNAL(
__string_is_trivial_iterator<_Iterator>::value, "The iterator type given to `__assign_trivial` must be trivial");
-
+ size_type __old_size = size();
size_type __cap = capacity();
if (__cap < __n) {
// Unlike `append` functions, if the input range points into the string itself, there is no case that the input
@@ -2591,12 +2723,17 @@ basic_string<_CharT, _Traits, _Allocator>::__assign_trivial(_Iterator __first, _
// object itself stays valid even if reallocation happens.
size_type __sz = size();
__grow_by_without_replace(__cap, __n - __cap, __sz, 0, __sz);
+ __annotate_increase(__n);
}
+ else if (__n > __old_size)
+ __annotate_increase(__n - __old_size);
pointer __p = __get_pointer();
for (; __first != __last; ++__p, (void) ++__first)
traits_type::assign(*__p, *__first);
traits_type::assign(*__p, value_type());
__set_size(__n);
+ if (__n < __old_size)
+ __annotate_shrink(__old_size);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2657,6 +2794,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_ty
{
if (__n)
{
+ __annotate_increase(__n);
value_type* __p = std::__to_address(__get_pointer());
traits_type::copy(__p + __sz, __s, __n);
__sz += __n;
@@ -2680,6 +2818,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
size_type __sz = size();
if (__cap - __sz < __n)
__grow_by_without_replace(__cap, __sz + __n - __cap, __sz, __sz, 0);
+ __annotate_increase(__n);
pointer __p = __get_pointer();
traits_type::assign(std::__to_address(__p) + __sz, __n, __c);
__sz += __n;
@@ -2699,6 +2838,7 @@ basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
size_type __sz = size();
if (__cap - __sz < __n)
__grow_by_without_replace(__cap, __sz + __n - __cap, __sz, __sz, 0);
+ __annotate_increase(__n);
pointer __p = __get_pointer();
__sz += __n;
__set_size(__sz);
@@ -2727,8 +2867,10 @@ basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
if (__sz == __cap)
{
__grow_by_without_replace(__cap, 1, __sz, __sz, 0);
+ __annotate_increase(1);
__is_short = false; // the string is always long after __grow_by
- }
+ } else
+ __annotate_increase(1);
pointer __p = __get_pointer();
if (__is_short)
{
@@ -2760,6 +2902,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(
{
if (__cap - __sz < __n)
__grow_by_without_replace(__cap, __sz + __n - __cap, __sz, __sz, 0);
+ __annotate_increase(__n);
pointer __p = __get_pointer() + __sz;
for (; __first != __last; ++__p, (void) ++__first)
traits_type::assign(*__p, *__first);
@@ -2825,6 +2968,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_t
{
if (__n)
{
+ __annotate_increase(__n);
value_type* __p = std::__to_address(__get_pointer());
size_type __n_move = __sz - __pos;
if (__n_move != 0)
@@ -2858,6 +3002,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n
value_type* __p;
if (__cap - __sz >= __n)
{
+ __annotate_increase(__n);
__p = std::__to_address(__get_pointer());
size_type __n_move = __sz - __pos;
if (__n_move != 0)
@@ -2966,6 +3111,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_ty
}
else
{
+ __annotate_increase(1);
__p = std::__to_address(__get_pointer());
size_type __n_move = __sz - __ip;
if (__n_move != 0)
@@ -2996,6 +3142,8 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
value_type* __p = std::__to_address(__get_pointer());
if (__n1 != __n2)
{
+ if (__n2 > __n1)
+ __annotate_increase(__n2 - __n1);
size_type __n_move = __sz - __pos - __n1;
if (__n_move != 0)
{
@@ -3040,20 +3188,19 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
__n1 = std::min(__n1, __sz - __pos);
size_type __cap = capacity();
value_type* __p;
- if (__cap - __sz + __n1 >= __n2)
- {
- __p = std::__to_address(__get_pointer());
- if (__n1 != __n2)
- {
- size_type __n_move = __sz - __pos - __n1;
- if (__n_move != 0)
- traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
- }
- }
- else
- {
- __grow_by_without_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
- __p = std::__to_address(__get_long_pointer());
+ if (__cap - __sz + __n1 >= __n2) {
+ __p = std::__to_address(__get_pointer());
+ if (__n1 != __n2) {
+ if (__n2 > __n1)
+ __annotate_increase(__n2 - __n1);
+ size_type __n_move = __sz - __pos - __n1;
+ if (__n_move != 0)
+ traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
+ }
+ } else {
+ __grow_by_without_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
+ __set_long_size(__sz - __n1 + __n2);
+ __p = std::__to_address(__get_long_pointer());
}
traits_type::assign(__p + __pos, __n2, __c);
return __null_terminate_at(__p, __sz - (__n1 - __n2));
@@ -3181,6 +3328,7 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20
void
basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
{
+ size_type __old_size = size();
if (__is_long())
{
traits_type::assign(*__get_long_pointer(), value_type());
@@ -3191,6 +3339,7 @@ basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
traits_type::assign(*__get_short_pointer(), value_type());
__set_short_size(0);
}
+ __annotate_shrink(__old_size);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -3253,6 +3402,7 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20
void
basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity)
{
+ __annotate_delete();
size_type __cap = capacity();
size_type __sz = size();
@@ -3309,6 +3459,7 @@ basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target
}
else
__set_short_size(__sz);
+ __annotate_new(__sz);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -3359,8 +3510,16 @@ basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
__alloc_traits::propagate_on_container_swap::value ||
__alloc_traits::is_always_equal::value ||
__alloc() == __str.__alloc(), "swapping non-equal allocators");
+ if (!__is_long())
+ __annotate_delete();
+ if (this != &__str && !__str.__is_long())
+ __str.__annotate_delete();
std::swap(__r_.first(), __str.__r_.first());
std::__swap_allocator(__alloc(), __str.__alloc());
+ if (!__is_long())
+ __annotate_new(__get_short_size());
+ if (this != &__str && !__str.__is_long())
+ __str.__annotate_new(__str.__get_short_size());
}
// find
@@ -3848,12 +4007,12 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20
void
basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
{
- clear();
- if(__is_long())
- {
- __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
- __r_.first() = __rep();
- }
+ clear();
+ if (__is_long()) {
+ __annotate_delete();
+ __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
+ __r_.first() = __rep();
+ }
}
// operator==
@@ -4104,6 +4263,7 @@ operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
_Traits::copy(__ptr, __lhs.data(), __lhs_sz);
_Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz);
_Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
+ __r.__annotate_new(__lhs_sz + __rhs_sz);
return __r;
}
@@ -4118,10 +4278,12 @@ operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& _
_String __r(__uninitialized_size_tag(),
__lhs_sz + __rhs_sz,
_String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
+ __r.__annotate_delete();
auto __ptr = std::__to_address(__r.__get_pointer());
_Traits::copy(__ptr, __lhs, __lhs_sz);
_Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz);
_Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
+ __r.__annotate_new(__lhs_sz + __rhs_sz);
return __r;
}
@@ -4135,10 +4297,12 @@ operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
_String __r(__uninitialized_size_tag(),
__rhs_sz + 1,
_String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
+ __r.__annotate_delete();
auto __ptr = std::__to_address(__r.__get_pointer());
_Traits::assign(__ptr, 1, __lhs);
_Traits::copy(__ptr + 1, __rhs.data(), __rhs_sz);
_Traits::assign(__ptr + 1 + __rhs_sz, 1, _CharT());
+ __r.__annotate_new(1 + __rhs_sz);
return __r;
}
@@ -4153,10 +4317,12 @@ operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT*
_String __r(__uninitialized_size_tag(),
__lhs_sz + __rhs_sz,
_String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
+ __r.__annotate_delete();
auto __ptr = std::__to_address(__r.__get_pointer());
_Traits::copy(__ptr, __lhs.data(), __lhs_sz);
_Traits::copy(__ptr + __lhs_sz, __rhs, __rhs_sz);
_Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
+ __r.__annotate_new(__lhs_sz + __rhs_sz);
return __r;
}
@@ -4170,10 +4336,12 @@ operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
_String __r(__uninitialized_size_tag(),
__lhs_sz + 1,
_String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
+ __r.__annotate_delete();
auto __ptr = std::__to_address(__r.__get_pointer());
_Traits::copy(__ptr, __lhs.data(), __lhs_sz);
_Traits::assign(__ptr + __lhs_sz, 1, __rhs);
_Traits::assign(__ptr + 1 + __lhs_sz, 1, _CharT());
+ __r.__annotate_new(__lhs_sz + 1);
return __r;
}
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
index e1d20662e41de89..de7f093f1c3a8e4 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
@@ -15,6 +15,7 @@
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
#include "test_macros.h"
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp
index 3a308de9b7569a3..7c33f7b5dcca8f6 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp
@@ -15,31 +15,38 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s) {
s.clear();
assert(s.size() == 0);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
TEST_CONSTEXPR_CXX20 void test_string() {
S s;
test(s);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
s.assign(10, 'a');
s.erase(5);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
test(s);
s.assign(100, 'a');
s.erase(50);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
test(s);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
TEST_CONSTEXPR_CXX20 bool test() {
test_string<std::string>();
#if TEST_STD_VER >= 11
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+ test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#endif
return true;
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
index 03e3cf2f9d7d38e..31b66c3fb36e753 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
@@ -18,6 +18,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
void test(typename S::size_type min_cap, typename S::size_type erased_index) {
@@ -33,6 +34,7 @@ void test(typename S::size_type min_cap, typename S::size_type erased_index) {
assert(s == s0);
assert(s.capacity() <= old_cap);
assert(s.capacity() >= s.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
@@ -46,6 +48,7 @@ bool test() {
test_string<std::string>();
#if TEST_STD_VER >= 11
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+ test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#endif
return true;
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.asan.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.asan.pass.cpp
new file mode 100644
index 000000000000000..31db1629b5c6e0d
--- /dev/null
+++ b/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.asan.pass.cpp
@@ -0,0 +1,81 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+#include <string>
+#include <cassert>
+
+#include "test_macros.h"
+#include "asan_testing.h"
+
+template <class S>
+void test() {
+ S short_s1(3, 'a'), long_s1(100, 'c');
+ short_s1.reserve(0x1337);
+ long_s1.reserve(0x1337);
+
+ LIBCPP_ASSERT(is_string_asan_correct(short_s1));
+ LIBCPP_ASSERT(is_string_asan_correct(long_s1));
+#if TEST_STD_VER >= 11
+ short_s1.shrink_to_fit();
+ long_s1.shrink_to_fit();
+
+ LIBCPP_ASSERT(is_string_asan_correct(short_s1));
+ LIBCPP_ASSERT(is_string_asan_correct(long_s1));
+#endif
+ short_s1.clear();
+ long_s1.clear();
+
+ LIBCPP_ASSERT(is_string_asan_correct(short_s1));
+ LIBCPP_ASSERT(is_string_asan_correct(long_s1));
+#if TEST_STD_VER >= 11
+ short_s1.shrink_to_fit();
+ long_s1.shrink_to_fit();
+
+ LIBCPP_ASSERT(is_string_asan_correct(short_s1));
+ LIBCPP_ASSERT(is_string_asan_correct(long_s1));
+#endif
+ S short_s2(3, 'a'), long_s2(100, 'c');
+ short_s2.reserve(0x1);
+ long_s2.reserve(0x1);
+
+ LIBCPP_ASSERT(is_string_asan_correct(short_s2));
+ LIBCPP_ASSERT(is_string_asan_correct(long_s2));
+}
+
+int main(int, char**) {
+ {
+ using S = std::string;
+ test<S>();
+ }
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ {
+ using S = std::wstring;
+ test<S>();
+ }
+#endif
+#if TEST_STD_VER >= 11
+ {
+ using S = std::u16string;
+ test<S>();
+ }
+ {
+ using S = std::u32string;
+ test<S>();
+ }
+#endif
+#if TEST_STD_VER >= 20
+ {
+ using S = std::u8string;
+ test<S>();
+ }
+#endif
+
+ return 0;
+}
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp
index bb804bf328b3b8d..6e0485c051f0dce 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp
@@ -20,6 +20,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp
index bbe6551a0ff1181..00f5cccd30d6b73 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp
@@ -19,6 +19,7 @@
#include "make_string.h"
#include "test_macros.h"
+#include "asan_testing.h"
template <class S>
constexpr void test_appending(std::size_t k, size_t N, size_t new_capacity) {
@@ -76,11 +77,14 @@ constexpr bool test() {
void test_value_categories() {
std::string s;
s.resize_and_overwrite(10, [](char*&&, std::size_t&&) { return 0; });
+ LIBCPP_ASSERT(is_string_asan_correct(s));
s.resize_and_overwrite(10, [](char* const&, const std::size_t&) { return 0; });
+ LIBCPP_ASSERT(is_string_asan_correct(s));
struct RefQualified {
int operator()(char*, std::size_t) && { return 0; }
};
s.resize_and_overwrite(10, RefQualified{});
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
int main(int, char**) {
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
index 487b12d9df87f33..5f9c3febc9ad0cb 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
@@ -16,14 +16,18 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, S expected) {
- if (n <= s.max_size()) {
- s.resize(n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- }
+
+ if (n <= s.max_size())
+ {
+ s.resize(n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
@@ -61,6 +65,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
test_string<std::string>();
#if TEST_STD_VER >= 11
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+ test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#endif
return true;
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
index 3b6adc0b0afeb19..31f047c6b5fdc35 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
@@ -16,14 +16,18 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, typename S::value_type c, S expected) {
- if (n <= s.max_size()) {
- s.resize(n, c);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- }
+
+ if (n <= s.max_size())
+ {
+ s.resize(n, c);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
@@ -57,6 +61,16 @@ TEST_CONSTEXPR_CXX20 void test_string() {
'a',
S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
test(S(), S::npos, 'a', S("not going to happen"));
+ //ASan:
+ test(S(), 21, 'a', S("aaaaaaaaaaaaaaaaaaaaa"));
+ test(S(), 22, 'a', S("aaaaaaaaaaaaaaaaaaaaaa"));
+ test(S(), 23, 'a', S("aaaaaaaaaaaaaaaaaaaaaaa"));
+ test(S(), 24, 'a', S("aaaaaaaaaaaaaaaaaaaaaaaa"));
+ test(S(), 29, 'a', S("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
+ test(S(), 30, 'a', S("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
+ test(S(), 31, 'a', S("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
+ test(S(), 32, 'a', S("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
+ test(S(), 33, 'a', S("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
}
TEST_CONSTEXPR_CXX20 bool test() {
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp
index 1efebfc9cea561b..ac897f116565961 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp
@@ -15,6 +15,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s) {
@@ -25,6 +26,7 @@ TEST_CONSTEXPR_CXX20 void test(S s) {
assert(s == s0);
assert(s.capacity() <= old_cap);
assert(s.capacity() >= s.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
@@ -39,12 +41,18 @@ TEST_CONSTEXPR_CXX20 void test_string() {
s.assign(100, 'a');
s.erase(50);
test(s);
+
+ s.assign(100, 'a');
+ for(int i = 0; i < 90; ++i)
+ s.erase(1);
+ test(s);
}
TEST_CONSTEXPR_CXX20 bool test() {
test_string<std::string>();
#if TEST_STD_VER >= 11
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+ test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#endif
return true;
diff --git a/libcxx/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp
index a6b625b7b0e8113..5d595746f8959f2 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp
@@ -23,22 +23,26 @@
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S, class SV>
TEST_CONSTEXPR_CXX20 void test(SV sv, std::size_t pos, std::size_t n) {
- typedef typename S::traits_type T;
- typedef typename S::allocator_type A;
- typedef typename S::size_type Size;
- if (pos <= sv.size()) {
- S s2(sv, static_cast<Size>(pos), static_cast<Size>(n));
- LIBCPP_ASSERT(s2.__invariants());
- assert(pos <= sv.size());
- std::size_t rlen = std::min(sv.size() - pos, n);
- assert(s2.size() == rlen);
- assert(T::compare(s2.data(), sv.data() + pos, rlen) == 0);
- assert(s2.get_allocator() == A());
- assert(s2.capacity() >= s2.size());
- }
+
+ typedef typename S::traits_type T;
+ typedef typename S::allocator_type A;
+ typedef typename S::size_type Size;
+ if (pos <= sv.size())
+ {
+ S s2(sv, static_cast<Size>(pos), static_cast<Size>(n));
+ LIBCPP_ASSERT(s2.__invariants());
+ assert(pos <= sv.size());
+ std::size_t rlen = std::min(sv.size() - pos, n);
+ assert(s2.size() == rlen);
+ assert(T::compare(s2.data(), sv.data() + pos, rlen) == 0);
+ assert(s2.get_allocator() == A());
+ assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.cons/alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/alloc.pass.cpp
index 97a0566ba031b00..46a2d943691526d 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/alloc.pass.cpp
@@ -16,6 +16,7 @@
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test() {
@@ -31,8 +32,9 @@ TEST_CONSTEXPR_CXX20 void test() {
assert(s.size() == 0);
assert(s.capacity() >= s.size());
assert(s.get_allocator() == typename S::allocator_type());
- }
- {
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
+ {
#if TEST_STD_VER > 14
static_assert((noexcept(S{typename S::allocator_type{}})), "");
#elif TEST_STD_VER >= 11
@@ -46,7 +48,8 @@ TEST_CONSTEXPR_CXX20 void test() {
assert(s.size() == 0);
assert(s.capacity() >= s.size());
assert(s.get_allocator() == typename S::allocator_type(5));
- }
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
}
#if TEST_STD_VER >= 11
@@ -65,22 +68,22 @@ TEST_CONSTEXPR_CXX20 void test2() {
assert(s.size() == 0);
assert(s.capacity() >= s.size());
assert(s.get_allocator() == typename S::allocator_type());
- }
- {
-# if TEST_STD_VER > 14
- static_assert((noexcept(S{typename S::allocator_type{}})), "");
-# elif TEST_STD_VER >= 11
- static_assert((noexcept(S(typename S::allocator_type())) ==
- std::is_nothrow_copy_constructible<typename S::allocator_type>::value),
- "");
-# endif
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
+ {
+#if TEST_STD_VER > 14
+ static_assert((noexcept(S{typename S::allocator_type{}})), "" );
+#elif TEST_STD_VER >= 11
+ static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
+#endif
S s(typename S::allocator_type{});
LIBCPP_ASSERT(s.__invariants());
assert(s.data());
assert(s.size() == 0);
assert(s.capacity() >= s.size());
assert(s.get_allocator() == typename S::allocator_type());
- }
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
}
#endif
@@ -89,6 +92,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >();
#if TEST_STD_VER >= 11
test2<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
+ test2<std::basic_string<char, std::char_traits<char>, safe_allocator<char> > >();
test2<std::basic_string<char, std::char_traits<char>, explicit_allocator<char> > >();
#endif
diff --git a/libcxx/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp
index e7d18b4ca87179d..6b3a665ced447f5 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp
@@ -17,6 +17,7 @@
#include <cassert>
#include "test_macros.h"
+#include "asan_testing.h"
TEST_CONSTEXPR_CXX20 bool test() {
// Test that assignment from {} and {ptr, len} are allowed and are not
@@ -25,11 +26,13 @@ TEST_CONSTEXPR_CXX20 bool test() {
std::string s = "hello world";
s = {};
assert(s.empty());
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
{
std::string s = "hello world";
s = {"abc", 2};
assert(s == "ab");
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
return true;
diff --git a/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp
index 3cffc82e9483526..c011f07840c3c6a 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp
@@ -15,6 +15,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s1, typename S::value_type s2) {
@@ -24,6 +25,7 @@ TEST_CONSTEXPR_CXX20 void test(S s1, typename S::value_type s2) {
assert(s1.size() == 1);
assert(T::eq(s1[0], s2));
assert(s1.capacity() >= s1.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/copy.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/copy.pass.cpp
index 3afe76e88316f99..607adec0587d905 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/copy.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/copy.pass.cpp
@@ -16,6 +16,7 @@
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s1) {
@@ -24,6 +25,8 @@ TEST_CONSTEXPR_CXX20 void test(S s1) {
assert(s2 == s1);
assert(s2.capacity() >= s2.size());
assert(s2.get_allocator() == s1.get_allocator());
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc>
@@ -40,6 +43,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
test_string(test_allocator<char>(3));
#if TEST_STD_VER >= 11
test_string(min_allocator<char>());
+ test_string(safe_allocator<char>());
#endif
return true;
diff --git a/libcxx/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
index 6b0040376a424ec..aa8c1408e887202 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
@@ -16,6 +16,7 @@
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
#ifndef TEST_HAS_NO_EXCEPTIONS
struct alloc_imp {
@@ -83,6 +84,8 @@ TEST_CONSTEXPR_CXX20 void test(S s1, const typename S::allocator_type& a) {
assert(s2 == s1);
assert(s2.capacity() >= s2.size());
assert(s2.get_allocator() == a);
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp
index 8d0fcb3c6d2943f..cfc9f66b584c045 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp
@@ -16,6 +16,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s1, const S& s2) {
@@ -23,6 +24,8 @@ TEST_CONSTEXPR_CXX20 void test(S s1, const S& s2) {
LIBCPP_ASSERT(s1.__invariants());
assert(s1 == s2);
assert(s1.capacity() >= s1.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/default.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/default.pass.cpp
index 3993a40dd5a165c..fc263f9820cb5b7 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/default.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/default.pass.cpp
@@ -15,6 +15,7 @@
#include "test_macros.h"
#include "test_allocator.h"
+#include "asan_testing.h"
#if TEST_STD_VER >= 11
// Test the noexcept specification, which is a conforming extension
@@ -30,6 +31,7 @@ LIBCPP_STATIC_ASSERT(!std::is_nothrow_default_constructible<
TEST_CONSTEXPR_CXX20 bool test() {
std::string str;
assert(str.empty());
+ LIBCPP_ASSERT(is_string_asan_correct(str));
return true;
}
diff --git a/libcxx/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp
index 5b7e8bde2e6e877..67c34d0ba608865 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp
@@ -18,6 +18,7 @@
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
// clang-format off
template <template <class> class Alloc>
@@ -25,11 +26,19 @@ TEST_CONSTEXPR_CXX20 void test_string() {
{
std::basic_string<char, std::char_traits<char>, Alloc<char> > s = {'a', 'b', 'c'};
assert(s == "abc");
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
+ {
+ typedef std::basic_string<char, std::char_traits<char>, safe_allocator<char>> S;
+ S s = {'a', 'b', 'c'};
+ assert(s == "abc");
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
std::basic_string<wchar_t, std::char_traits<wchar_t>, Alloc<wchar_t> > s = {L'a', L'b', L'c'};
assert(s == L"abc");
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
#endif
}
diff --git a/libcxx/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp
index 88597daba121ac4..0ef13412ad2c502 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp
@@ -17,6 +17,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
// clang-format off
template <template <class> class Alloc>
@@ -27,6 +28,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {
S& result = (s = {'a', 'b', 'c'});
assert(s == "abc");
assert(&result == &s);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
@@ -43,7 +45,14 @@ TEST_CONSTEXPR_CXX20 void test_string() {
TEST_CONSTEXPR_CXX20 bool test() {
test_string<std::allocator>();
test_string<min_allocator>();
-
+ test_string<safe_allocator>();
+ {
+ typedef std::basic_string<char, std::char_traits<char>, safe_allocator<char>> S;
+ S s;
+ s = {'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a'};
+ assert(s == "aaaaaaaaaaaaaaaaaaaaaaaa");
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
return true;
}
diff --git a/libcxx/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp
index 2ef73e5ec8c1ade..c7db45a3c80e4bd 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp
@@ -21,6 +21,7 @@
#include "test_allocator.h"
#include "test_iterators.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class Alloc, class It>
TEST_CONSTEXPR_CXX20 void test(It first, It last) {
@@ -37,6 +38,7 @@ TEST_CONSTEXPR_CXX20 void test(It first, It last) {
}
assert(s2.get_allocator() == Alloc());
assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc, class It>
@@ -54,6 +56,7 @@ TEST_CONSTEXPR_CXX20 void test(It first, It last, const Alloc& a) {
}
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp
index 65762ccf89d9304..b9e35eff4446e1a 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp
@@ -29,6 +29,7 @@
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
class NotAnIterator {};
using NotAnInputIterator = std::back_insert_iterator<std::basic_string<char16_t>>;
diff --git a/libcxx/test/std/strings/basic.string/string.cons/move.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/move.pass.cpp
index f5ffebd35d50e92..d584ea651a0bc7e 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/move.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/move.pass.cpp
@@ -18,6 +18,7 @@
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s0) {
@@ -28,6 +29,9 @@ TEST_CONSTEXPR_CXX20 void test(S s0) {
assert(s2 == s1);
assert(s2.capacity() >= s2.size());
assert(s2.get_allocator() == s1.get_allocator());
+ LIBCPP_ASSERT(is_string_asan_correct(s0));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
index 0e5c72192adea64..cf7daf5ccf1a703 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
@@ -18,6 +18,7 @@
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s0, const typename S::allocator_type& a) {
@@ -28,6 +29,9 @@ TEST_CONSTEXPR_CXX20 void test(S s0, const typename S::allocator_type& a) {
assert(s2 == s1);
assert(s2.capacity() >= s2.size());
assert(s2.get_allocator() == a);
+ LIBCPP_ASSERT(is_string_asan_correct(s0));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
TEST_CONSTEXPR_CXX20 bool test() {
diff --git a/libcxx/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp
index 89cb44d62ef2b6c..1f46b96990abe69 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp
@@ -19,6 +19,7 @@
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s1, S s2) {
@@ -28,6 +29,9 @@ TEST_CONSTEXPR_CXX20 void test(S s1, S s2) {
LIBCPP_ASSERT(s2.__invariants());
assert(s1 == s0);
assert(s1.capacity() >= s1.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s0));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class S>
@@ -51,6 +55,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
test_string<std::string>();
#if TEST_STD_VER >= 11
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+ test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#endif
return true;
diff --git a/libcxx/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp
index 84a29df5b57bf16..6f9eafaa25e5ded 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp
@@ -19,6 +19,7 @@
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class Alloc, class charT>
TEST_CONSTEXPR_CXX20 void test(const charT* s) {
@@ -31,6 +32,7 @@ TEST_CONSTEXPR_CXX20 void test(const charT* s) {
assert(T::compare(s2.data(), s, n) == 0);
assert(s2.get_allocator() == Alloc());
assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc, class charT>
@@ -44,6 +46,7 @@ TEST_CONSTEXPR_CXX20 void test(const charT* s, const Alloc& a) {
assert(T::compare(s2.data(), s, n) == 0);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp
index 4b3027a2aad1183..742263d354a749e 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp
@@ -16,6 +16,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s1, const typename S::value_type* s2) {
@@ -25,6 +26,7 @@ TEST_CONSTEXPR_CXX20 void test(S s1, const typename S::value_type* s2) {
assert(s1.size() == T::length(s2));
assert(T::compare(s1.data(), s2, s1.size()) == 0);
assert(s1.capacity() >= s1.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
}
template <class S>
@@ -48,6 +50,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
test_string<std::string>();
#if TEST_STD_VER >= 11
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+ test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#endif
return true;
diff --git a/libcxx/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp
index e0dab72b5c6327e..bf662c05f9cef3a 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp
@@ -18,6 +18,7 @@
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class Alloc, class CharT>
TEST_CONSTEXPR_CXX20 void test(const CharT* s, unsigned n) {
@@ -29,6 +30,7 @@ TEST_CONSTEXPR_CXX20 void test(const CharT* s, unsigned n) {
assert(T::compare(s2.data(), s, n) == 0);
assert(s2.get_allocator() == Alloc());
assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc, class CharT>
@@ -41,6 +43,7 @@ TEST_CONSTEXPR_CXX20 void test(const CharT* s, unsigned n, const Alloc& a) {
assert(T::compare(s2.data(), s, n) == 0);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp
index 3afbcdffa6bdfe3..0e2f7ebbdafcc90 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp
@@ -19,6 +19,7 @@
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class Alloc, class charT>
TEST_CONSTEXPR_CXX20 void test(unsigned n, charT c) {
@@ -30,6 +31,7 @@ TEST_CONSTEXPR_CXX20 void test(unsigned n, charT c) {
assert(s2[i] == c);
assert(s2.get_allocator() == Alloc());
assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc, class charT>
@@ -42,6 +44,7 @@ TEST_CONSTEXPR_CXX20 void test(unsigned n, charT c, const Alloc& a) {
assert(s2[i] == c);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc, class Tp>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/string_view.pass.cpp
index 74fa76a013a6926..f9031da30367db8 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/string_view.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/string_view.pass.cpp
@@ -20,6 +20,7 @@
#include "min_allocator.h"
#include "test_allocator.h"
#include "test_macros.h"
+#include "asan_testing.h"
static_assert(!std::is_convertible<std::string_view, std::string const&>::value, "");
static_assert(!std::is_convertible<std::string_view, std::string>::value, "");
@@ -35,6 +36,7 @@ TEST_CONSTEXPR_CXX20 void test(std::basic_string_view<CharT> sv) {
assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
assert(s2.get_allocator() == Alloc());
assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
{
S s2;
@@ -44,6 +46,7 @@ TEST_CONSTEXPR_CXX20 void test(std::basic_string_view<CharT> sv) {
assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
assert(s2.get_allocator() == Alloc());
assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
}
@@ -58,6 +61,7 @@ TEST_CONSTEXPR_CXX20 void test(std::basic_string_view<CharT> sv, const Alloc& a)
assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
{
S s2(a);
@@ -67,6 +71,7 @@ TEST_CONSTEXPR_CXX20 void test(std::basic_string_view<CharT> sv, const Alloc& a)
assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
}
diff --git a/libcxx/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp
index 3c88f9e40fc0b3b..b66124b763a1b3e 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp
@@ -15,6 +15,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S, class SV>
TEST_CONSTEXPR_CXX20 void test(S s1, SV sv) {
@@ -24,6 +25,7 @@ TEST_CONSTEXPR_CXX20 void test(S s1, SV sv) {
assert(s1.size() == sv.size());
assert(T::compare(s1.data(), sv.data(), s1.size()) == 0);
assert(s1.capacity() >= s1.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
}
template <class S>
@@ -48,6 +50,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
test_string<std::string>();
#if TEST_STD_VER >= 11
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+ test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#endif
return true;
diff --git a/libcxx/test/std/strings/basic.string/string.cons/substr.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/substr.pass.cpp
index 693edab76b17b0c..c78651c0dfc2954 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/substr.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/substr.pass.cpp
@@ -26,6 +26,7 @@
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S str, unsigned pos) {
@@ -33,14 +34,16 @@ TEST_CONSTEXPR_CXX20 void test(S str, unsigned pos) {
typedef typename S::allocator_type A;
if (pos <= str.size()) {
- S s2(str, pos);
- LIBCPP_ASSERT(s2.__invariants());
- typename S::size_type rlen = str.size() - pos;
- assert(s2.size() == rlen);
- assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
- assert(s2.get_allocator() == A());
- assert(s2.capacity() >= s2.size());
- }
+
+ S s2(str, pos);
+ LIBCPP_ASSERT(s2.__invariants());
+ typename S::size_type rlen = str.size() - pos;
+ assert(s2.size() == rlen);
+ assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
+ assert(s2.get_allocator() == A());
+ assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
@@ -55,17 +58,20 @@ TEST_CONSTEXPR_CXX20 void test(S str, unsigned pos) {
template <class S>
TEST_CONSTEXPR_CXX20 void test(S str, unsigned pos, unsigned n) {
- typedef typename S::traits_type T;
- typedef typename S::allocator_type A;
- if (pos <= str.size()) {
- S s2(str, pos, n);
- LIBCPP_ASSERT(s2.__invariants());
- typename S::size_type rlen = std::min<typename S::size_type>(str.size() - pos, n);
- assert(s2.size() == rlen);
- assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
- assert(s2.get_allocator() == A());
- assert(s2.capacity() >= s2.size());
- }
+
+ typedef typename S::traits_type T;
+ typedef typename S::allocator_type A;
+ if (pos <= str.size())
+ {
+ S s2(str, pos, n);
+ LIBCPP_ASSERT(s2.__invariants());
+ typename S::size_type rlen = std::min<typename S::size_type>(str.size() - pos, n);
+ assert(s2.size() == rlen);
+ assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
+ assert(s2.get_allocator() == A());
+ assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
@@ -83,14 +89,16 @@ TEST_CONSTEXPR_CXX20 void test(S str, unsigned pos, unsigned n, const typename S
typedef typename S::traits_type T;
if (pos <= str.size()) {
- S s2(str, pos, n, a);
- LIBCPP_ASSERT(s2.__invariants());
- typename S::size_type rlen = std::min<typename S::size_type>(str.size() - pos, n);
- assert(s2.size() == rlen);
- assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
- assert(s2.get_allocator() == a);
- assert(s2.capacity() >= s2.size());
- }
+
+ S s2(str, pos, n, a);
+ LIBCPP_ASSERT(s2.__invariants());
+ typename S::size_type rlen = std::min<typename S::size_type>(str.size() - pos, n);
+ assert(s2.size() == rlen);
+ assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
+ assert(s2.get_allocator() == a);
+ assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp
index 6c5049f16bc6192..b5805693c5902c4 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp
@@ -18,7 +18,7 @@
#include "test_macros.h"
#include "min_allocator.h"
#include "nasty_string.h"
-
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test() {
using CharT = typename S::value_type;
@@ -26,6 +26,7 @@ TEST_CONSTEXPR_CXX20 void test() {
S s(CONVERT_TO_CSTRING(CharT, "123"));
s.append({CharT('a'), CharT('b'), CharT('c')});
assert(s == CONVERT_TO_CSTRING(CharT, "123abc"));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
TEST_CONSTEXPR_CXX20 bool test() {
@@ -40,6 +41,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
test<std::u32string>();
test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+ test<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#ifndef TEST_HAS_NO_NASTY_STRING
test<nasty_string>();
#endif
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
index 2982cfe77042c0d..115dbc003b5e0fe 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
@@ -17,12 +17,14 @@
#include "test_macros.h"
#include "test_iterators.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S, class It>
TEST_CONSTEXPR_CXX20 void test(S s, It first, It last, S expected) {
s.append(first, last);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
#ifndef TEST_HAS_NO_EXCEPTIONS
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
index 68f5838ccf2f02a..97ca09adc56bd42 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
@@ -16,12 +16,14 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, S expected) {
s.append(str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
index b98c91cf097b1a0..7efbc4cdf41f6f7 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
@@ -17,12 +17,14 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, typename S::size_type n, S expected) {
s.append(str, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp
index 0b8e5f65c15e94d..233cafffa6981f6 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp
@@ -16,6 +16,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
struct VeryLarge {
long long a;
@@ -61,6 +62,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, typename S::value_type c, S expected) {
s.push_back(c);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp
index eb0728456df5be4..8a01ec34a189e2d 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp
@@ -16,12 +16,14 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, typename S::value_type c, S expected) {
s.append(n, c);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp
index 21f2ff53004d158..3cc5627e18857f3 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp
@@ -16,12 +16,14 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, S str, S expected) {
s.append(str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
index 902d29c53ac69f5..d4991dc2caa4602 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
@@ -18,14 +18,18 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected) {
- if (pos <= str.size()) {
- s.append(str, pos, n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- }
+
+ if (pos <= str.size())
+ {
+ s.append(str, pos, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
index a2a954cb94aac6a..0f38571d521e3ae 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
@@ -17,14 +17,18 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S, class SV>
TEST_CONSTEXPR_CXX20 void test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected) {
- if (pos <= sv.size()) {
- s.assign(sv, pos, n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- }
+
+ if (pos <= sv.size())
+ {
+ s.assign(sv, pos, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/initializer_list.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/initializer_list.pass.cpp
index ba55f30785e94f4..484ad723e7c7e21 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/initializer_list.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/initializer_list.pass.cpp
@@ -17,18 +17,21 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test_string() {
S s("123");
s.assign({'a', 'b', 'c'});
assert(s == "abc");
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
TEST_CONSTEXPR_CXX20 bool test() {
test_string<std::string>();
#if TEST_STD_VER >= 11
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
+ test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char> > >();
#endif
return true;
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
index b2ca4fb5ddd9370..22238bf52a05718 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
@@ -17,12 +17,14 @@
#include "test_macros.h"
#include "test_iterators.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S, class It>
TEST_CONSTEXPR_CXX20 void test(S s, It first, It last, S expected) {
s.assign(first, last);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
#ifndef TEST_HAS_NO_EXCEPTIONS
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
index 11e12c318a2e800..1f97c72e13a6866 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
@@ -16,12 +16,14 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, S expected) {
s.assign(str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
index 2738a9a6ffad594..53435be2ef9dafd 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
@@ -17,12 +17,14 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, typename S::size_type n, S expected) {
s.assign(str, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp
index b52c66103395f19..1b3a4c41fb710ee 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp
@@ -16,12 +16,14 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, typename S::value_type c, S expected) {
s.assign(n, c);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp
index f39b7f66c4b187a..8b310630bf07ab8 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp
@@ -18,12 +18,15 @@
#include "nasty_string.h"
#include "min_allocator.h"
#include "test_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S dest, S src) {
dest.assign(src);
LIBCPP_ASSERT(dest.__invariants());
assert(dest == src);
+ LIBCPP_ASSERT(is_string_asan_correct(src));
+ LIBCPP_ASSERT(is_string_asan_correct(dest));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
index 9448452bafad9c3..be9bdaa473e7dd8 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
@@ -18,14 +18,18 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected) {
- if (pos <= str.size()) {
- s.assign(str, pos, n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- }
+
+ if (pos <= str.size())
+ {
+ s.assign(str, pos, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
index e1904baeb9033b0..ceb0d4d44410e6b 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
@@ -17,6 +17,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S str, typename S::value_type* s, typename S::size_type n, typename S::size_type pos) {
@@ -25,9 +26,12 @@ TEST_CONSTEXPR_CXX20 void test(S str, typename S::value_type* s, typename S::siz
typename S::size_type r = cs.copy(s, n, pos);
typename S::size_type rlen = std::min(n, cs.size() - pos);
assert(r == rlen);
- for (r = 0; r < rlen; ++r)
- assert(S::traits_type::eq(cs[pos + r], s[r]));
- }
+ LIBCPP_ASSERT(is_string_asan_correct(str));
+ LIBCPP_ASSERT(is_string_asan_correct(cs));
+
+ for (r = 0; r < rlen; ++r)
+ assert(S::traits_type::eq(cs[pos+r], s[r]));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp
index 03c5b965537c6fe..b79a8c3606b67b0 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp
@@ -15,6 +15,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::difference_type pos, S expected) {
@@ -24,6 +25,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, typename S::difference_type pos, S expected)
assert(s[s.size()] == typename S::value_type());
assert(s == expected);
assert(i - s.begin() == pos);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp
index f092ad718cdaa89..125be1bf262fea8 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp
@@ -15,6 +15,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::difference_type pos, typename S::difference_type n, S expected) {
@@ -25,6 +26,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, typename S::difference_type pos, typename S:
assert(s[s.size()] == typename S::value_type());
assert(s == expected);
assert(i - s.begin() == pos);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.asan.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.asan.pass.cpp
new file mode 100644
index 000000000000000..30d793beeeff563
--- /dev/null
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.asan.pass.cpp
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <string>
+
+#include <string>
+#include <cassert>
+
+#include "test_macros.h"
+#include "asan_testing.h"
+
+template <class CharT>
+void test(const CharT val) {
+ using S = std::basic_string<CharT>;
+
+ S s;
+ while (s.size() < 8000) {
+ s.push_back(val);
+
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
+ while (s.size() > 0) {
+ s.pop_back();
+
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
+}
+
+int main(int, char**) {
+ {
+ using CharT = char;
+ test<CharT>('x');
+ }
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ {
+ using CharT = wchar_t;
+ test<CharT>(L'x');
+ }
+#endif
+#if TEST_STD_VER >= 11
+ {
+ using CharT = char16_t;
+ test<CharT>(u'x');
+ }
+ {
+ using CharT = char32_t;
+ test<CharT>(U'x');
+ }
+#endif
+#if TEST_STD_VER >= 20
+ {
+ using CharT = char8_t;
+ test<CharT>(u8'x');
+ }
+#endif
+
+ return 0;
+}
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp
index 9c63fa47a7e4a7f..ba717ac8a7bc1e2 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp
@@ -15,6 +15,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, S expected) {
@@ -22,6 +23,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, S expected) {
LIBCPP_ASSERT(s.__invariants());
assert(s[s.size()] == typename S::value_type());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
@@ -35,6 +37,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
test_string<std::string>();
#if TEST_STD_VER >= 11
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+ test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#endif
return true;
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
index 610256061a5f2cd..8d785ea783856ea 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
@@ -17,17 +17,21 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos, typename S::size_type n, S expected) {
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size) {
- s.erase(pos, n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s[s.size()] == typename S::value_type());
- assert(s == expected);
- }
+
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size)
+ {
+ s.erase(pos, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s[s.size()] == typename S::value_type());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp
index bc3ce511ab5c221..39fc648b95f3924 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp
@@ -16,18 +16,21 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S& s, typename S::const_iterator p, typename S::value_type c, S expected) {
- bool sufficient_cap = s.size() < s.capacity();
- typename S::difference_type pos = p - s.begin();
- typename S::iterator i = s.insert(p, c);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- assert(i - s.begin() == pos);
- assert(*i == c);
- if (sufficient_cap)
- assert(i == p);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ bool sufficient_cap = s.size() < s.capacity();
+ typename S::difference_type pos = p - s.begin();
+ typename S::iterator i = s.insert(p, c);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ assert(i - s.begin() == pos);
+ assert(*i == c);
+ if (sufficient_cap)
+ assert(i == p);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
@@ -53,6 +56,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
test_string<std::string>();
#if TEST_STD_VER >= 11
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+ test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#endif
return true;
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_initializer_list.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_initializer_list.pass.cpp
index 876cc9ecd14c6a8..60a925307d30f23 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_initializer_list.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_initializer_list.pass.cpp
@@ -17,6 +17,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test_string() {
@@ -24,6 +25,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {
typename S::iterator i = s.insert(s.begin() + 3, {'a', 'b', 'c'});
assert(i - s.begin() == 3);
assert(s == "123abc456");
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
TEST_CONSTEXPR_CXX20 bool test() {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
index e3d0f1322e85de2..96b8c1e3b74e2a7 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
@@ -17,6 +17,7 @@
#include "test_macros.h"
#include "test_iterators.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S, class It>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::difference_type pos, It first, It last, S expected) {
@@ -25,6 +26,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, typename S::difference_type pos, It first, I
LIBCPP_ASSERT(s.__invariants());
assert(i - s.begin() == pos);
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
#ifndef TEST_HAS_NO_EXCEPTIONS
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp
index 1e0d16e4cc2e172..aeaf898e5330dcd 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp
@@ -15,6 +15,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
@@ -24,6 +25,7 @@ test(S s, typename S::difference_type pos, typename S::size_type n, typename S::
LIBCPP_ASSERT(s.__invariants());
assert(i - s.begin() == pos);
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
index 359fd999598f889..ec436f223b739f0 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
@@ -17,16 +17,20 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos, const typename S::value_type* str, S expected) {
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size) {
- s.insert(pos, str);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- }
+
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size)
+ {
+ s.insert(pos, str);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
index 44f20ff63cc0ca5..8071499190d1b34 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
@@ -17,17 +17,21 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, const typename S::value_type* str, typename S::size_type n, S expected) {
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size) {
- s.insert(pos, str, n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- }
+
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size)
+ {
+ s.insert(pos, str, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
index 2396b7e2f54df73..73b5e815d0dab09 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
@@ -17,17 +17,21 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, typename S::size_type n, typename S::value_type str, S expected) {
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size) {
- s.insert(pos, n, str);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- }
+
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size)
+ {
+ s.insert(pos, n, str);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
index 1b908ac464c3134..8a596d9fc93e994 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
@@ -17,16 +17,20 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos, S str, S expected) {
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size) {
- s.insert(pos, str);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- }
+
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size)
+ {
+ s.insert(pos, str);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
index 1a8f6b35b42c445..0e97da338cd4dca 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
@@ -19,17 +19,21 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos1, S str, typename S::size_type pos2, typename S::size_type n, S expected) {
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos1 <= old_size && pos2 <= str.size()) {
- s.insert(pos1, str, pos2, n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- }
+
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos1 <= old_size && pos2 <= str.size())
+ {
+ s.insert(pos1, str, pos2, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/char.pass.cpp
index 1e03d8c1b614741..cdf0b3538f3f90b 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/char.pass.cpp
@@ -15,12 +15,14 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::value_type str, S expected) {
s += str;
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/initializer_list.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/initializer_list.pass.cpp
index e7334b96276a5f8..dd4db110590965a 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/initializer_list.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/initializer_list.pass.cpp
@@ -17,12 +17,14 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test_string() {
S s("123");
s += {'a', 'b', 'c'};
assert(s == "123abc");
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
TEST_CONSTEXPR_CXX20 bool test() {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp
index 2d8c535b354c22f..4a77cc594cd9147 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp
@@ -15,12 +15,14 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, S expected) {
s += str;
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp
index e02ced737ae16a2..62a9cf606e26e72 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp
@@ -16,12 +16,14 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, S str, S expected) {
s += str;
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp
index 35db1d636819169..28a90b247c3c6d9 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp
@@ -17,6 +17,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos1, typename S::size_type n1, S str, S expected) {
@@ -29,6 +30,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos1, typename S::size
assert(s == expected);
typename S::size_type rlen = str.size();
assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
@@ -292,6 +294,7 @@ int main(int, char**) {
test<std::string>();
#if TEST_STD_VER >= 11
test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+ test<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#endif
return 0;
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
index 004a51926285394..58faf49e3b2033d 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
@@ -23,6 +23,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S, class SV>
TEST_CONSTEXPR_CXX20 void
@@ -43,13 +44,15 @@ test(S s,
const SizeT old_size = s.size();
S s0 = s;
if (pos1 <= old_size && pos2 <= sv.size()) {
- s.replace(pos1, n1, sv, pos2, n2);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- SizeT xlen = std::min<SizeT>(n1, old_size - pos1);
- SizeT rlen = std::min<SizeT>(n2, sv.size() - pos2);
- assert(s.size() == old_size - xlen + rlen);
- }
+
+ s.replace(pos1, n1, sv, pos2, n2);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ SizeT xlen = std::min<SizeT>(n1, old_size - pos1);
+ SizeT rlen = std::min<SizeT>(n2, sv.size() - pos2);
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
index a7282615e485541..c425c4984e66ab6 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
@@ -18,20 +18,24 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, typename S::size_type n1, const typename S::value_type* str, S expected) {
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size) {
- s.replace(pos, n1, str);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- typename S::size_type xlen = std::min(n1, old_size - pos);
- typename S::size_type rlen = S::traits_type::length(str);
- assert(s.size() == old_size - xlen + rlen);
- }
+
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size)
+ {
+ s.replace(pos, n1, str);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type xlen = std::min(n1, old_size - pos);
+ typename S::size_type rlen = S::traits_type::length(str);
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
@@ -377,6 +381,7 @@ int main(int, char**) {
test<std::string>();
#if TEST_STD_VER >= 11
test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+ test<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#endif
return 0;
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
index 7ef63bdf313ddaf..b854fa9bd50470e 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
@@ -18,6 +18,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
@@ -27,16 +28,19 @@ test(S s,
const typename S::value_type* str,
typename S::size_type n2,
S expected) {
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size) {
- s.replace(pos, n1, str, n2);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- typename S::size_type xlen = std::min(n1, old_size - pos);
- typename S::size_type rlen = n2;
- assert(s.size() == old_size - xlen + rlen);
- }
+
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size)
+ {
+ s.replace(pos, n1, str, n2);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type xlen = std::min(n1, old_size - pos);
+ typename S::size_type rlen = n2;
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
@@ -1341,6 +1345,7 @@ int main(int, char**) {
test<std::string>();
#if TEST_STD_VER >= 11
test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+ test<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#endif
return 0;
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
index 8841318c1d4df5b..067826cd3fc36d9 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
@@ -18,6 +18,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
@@ -27,16 +28,19 @@ test(S s,
typename S::size_type n2,
typename S::value_type c,
S expected) {
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size) {
- s.replace(pos, n1, n2, c);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- typename S::size_type xlen = std::min(n1, old_size - pos);
- typename S::size_type rlen = n2;
- assert(s.size() == old_size - xlen + rlen);
- }
+
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size)
+ {
+ s.replace(pos, n1, n2, c);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type xlen = std::min(n1, old_size - pos);
+ typename S::size_type rlen = n2;
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
index fab2beeabd5721a..a56313ca09396a2 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
@@ -18,19 +18,23 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos1, typename S::size_type n1, S str, S expected) {
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos1 <= old_size) {
- s.replace(pos1, n1, str);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- typename S::size_type xlen = std::min(n1, old_size - pos1);
- typename S::size_type rlen = str.size();
- assert(s.size() == old_size - xlen + rlen);
- }
+
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos1 <= old_size)
+ {
+ s.replace(pos1, n1, str);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type xlen = std::min(n1, old_size - pos1);
+ typename S::size_type rlen = str.size();
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
index 073de60289857ae..972213155180994 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
@@ -22,6 +22,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
@@ -32,16 +33,19 @@ test(S s,
typename S::size_type pos2,
typename S::size_type n2,
S expected) {
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos1 <= old_size && pos2 <= str.size()) {
- s.replace(pos1, n1, str, pos2, n2);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- typename S::size_type xlen = std::min(n1, old_size - pos1);
- typename S::size_type rlen = std::min(n2, str.size() - pos2);
- assert(s.size() == old_size - xlen + rlen);
- }
+
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos1 <= old_size && pos2 <= str.size())
+ {
+ s.replace(pos1, n1, str, pos2, n2);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type xlen = std::min(n1, old_size - pos1);
+ typename S::size_type rlen = std::min(n2, str.size() - pos2);
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_view.pass.cpp
index cec8cc0c52dd9f3..316bb01db43d36e 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_view.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_view.pass.cpp
@@ -18,19 +18,23 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S, class SV>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos1, typename S::size_type n1, SV sv, S expected) {
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos1 <= old_size) {
- s.replace(pos1, n1, sv);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- typename S::size_type xlen = std::min(n1, old_size - pos1);
- typename S::size_type rlen = sv.size();
- assert(s.size() == old_size - xlen + rlen);
- }
+
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos1 <= old_size)
+ {
+ s.replace(pos1, n1, sv);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type xlen = std::min(n1, old_size - pos1);
+ typename S::size_type rlen = sv.size();
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.asan.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.asan.pass.cpp
new file mode 100644
index 000000000000000..3cabb3b797733f3
--- /dev/null
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.asan.pass.cpp
@@ -0,0 +1,102 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+#include <string>
+#include <cassert>
+
+#include "test_macros.h"
+#include "asan_testing.h"
+
+template <class CharT>
+void test(const CharT val) {
+ using S = std::basic_string<CharT>;
+
+ S empty_s;
+ S short_s(3, val);
+ S long_s(1100, val);
+
+ std::swap(empty_s, empty_s);
+ std::swap(short_s, short_s);
+ std::swap(long_s, long_s);
+ LIBCPP_ASSERT(is_string_asan_correct(empty_s));
+ LIBCPP_ASSERT(is_string_asan_correct(short_s));
+ LIBCPP_ASSERT(is_string_asan_correct(long_s));
+
+ std::swap(empty_s, short_s);
+ LIBCPP_ASSERT(is_string_asan_correct(empty_s));
+ LIBCPP_ASSERT(is_string_asan_correct(short_s));
+
+ std::swap(empty_s, short_s);
+ LIBCPP_ASSERT(is_string_asan_correct(empty_s));
+ LIBCPP_ASSERT(is_string_asan_correct(short_s));
+
+ std::swap(empty_s, long_s);
+ LIBCPP_ASSERT(is_string_asan_correct(empty_s));
+ LIBCPP_ASSERT(is_string_asan_correct(long_s));
+
+ std::swap(empty_s, long_s);
+ LIBCPP_ASSERT(is_string_asan_correct(empty_s));
+ LIBCPP_ASSERT(is_string_asan_correct(long_s));
+
+ std::swap(short_s, long_s);
+ LIBCPP_ASSERT(is_string_asan_correct(short_s));
+ LIBCPP_ASSERT(is_string_asan_correct(long_s));
+
+ std::swap(short_s, long_s);
+ LIBCPP_ASSERT(is_string_asan_correct(short_s));
+ LIBCPP_ASSERT(is_string_asan_correct(long_s));
+
+ S long_s2(11100, val);
+
+ std::swap(long_s, long_s2);
+ LIBCPP_ASSERT(is_string_asan_correct(long_s));
+ LIBCPP_ASSERT(is_string_asan_correct(long_s2));
+
+ std::swap(long_s, long_s2);
+ LIBCPP_ASSERT(is_string_asan_correct(long_s));
+ LIBCPP_ASSERT(is_string_asan_correct(long_s2));
+
+ S long_s3(111, val);
+
+ std::swap(long_s, long_s3);
+ LIBCPP_ASSERT(is_string_asan_correct(long_s));
+ LIBCPP_ASSERT(is_string_asan_correct(long_s2));
+}
+
+int main(int, char**) {
+ {
+ using CharT = char;
+ test<CharT>('x');
+ }
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ {
+ using CharT = wchar_t;
+ test<CharT>(L'x');
+ }
+#endif
+#if TEST_STD_VER >= 11
+ {
+ using CharT = char16_t;
+ test<CharT>(u'x');
+ }
+ {
+ using CharT = char32_t ;
+ test<CharT>(U'x');
+ }
+#endif
+#if TEST_STD_VER >= 20
+ {
+ using CharT = char8_t;
+ test<CharT>(u8'x');
+ }
+#endif
+
+ return 0;
+}
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.pass.cpp
index 3d9ec016bcfbd3a..dd5bc2eea57ce02 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.pass.cpp
@@ -17,6 +17,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s1, S s2) {
@@ -27,6 +28,8 @@ TEST_CONSTEXPR_CXX20 void test(S s1, S s2) {
LIBCPP_ASSERT(s2.__invariants());
assert(s1 == s2_);
assert(s2 == s1_);
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string.special/swap.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string.special/swap.pass.cpp
index da6fc11c14329f4..2d2c770b259294f 100644
--- a/libcxx/test/std/strings/basic.string/string.nonmembers/string.special/swap.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string.special/swap.pass.cpp
@@ -19,6 +19,7 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s1, S s2) {
@@ -29,6 +30,8 @@ TEST_CONSTEXPR_CXX20 void test(S s1, S s2) {
LIBCPP_ASSERT(s2.__invariants());
assert(s1 == s2_);
assert(s2 == s1_);
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/char_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/char_string.pass.cpp
index 82a591e0533628d..14f3c988f64e8a6 100644
--- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/char_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/char_string.pass.cpp
@@ -22,10 +22,12 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test0(typename S::value_type lhs, const S& rhs, const S& x) {
assert(lhs + rhs == x);
+ LIBCPP_ASSERT(is_string_asan_correct(lhs + rhs));
}
#if TEST_STD_VER >= 11
diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_char.pass.cpp
index 66cbac28f9f2c3a..7b38caeeee0e884 100644
--- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_char.pass.cpp
@@ -22,10 +22,12 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test0(const S& lhs, typename S::value_type rhs, const S& x) {
assert(lhs + rhs == x);
+ LIBCPP_ASSERT(is_string_asan_correct(lhs + rhs));
}
#if TEST_STD_VER >= 11
diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_pointer.pass.cpp
index 2802189f843c59c..aab70696a1d0756 100644
--- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_pointer.pass.cpp
@@ -22,10 +22,12 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test0(const S& lhs, const typename S::value_type* rhs, const S& x) {
assert(lhs + rhs == x);
+ LIBCPP_ASSERT(is_string_asan_correct(lhs + rhs));
}
#if TEST_STD_VER >= 11
diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_string.pass.cpp
index f8ebb98767a8375..df130fc63b3e7bc 100644
--- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_string.pass.cpp
@@ -34,10 +34,12 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "asan_testing.h"
template <class S>
TEST_CONSTEXPR_CXX20 void test0(const S& lhs, const S& rhs, const S& x) {
assert(lhs + rhs == x);
+ LIBCPP_ASSERT(is_string_asan_correct(lhs + rhs));
}
#if TEST_STD_VER >= 11
diff --git a/libcxx/test/support/asan_testing.h b/libcxx/test/support/asan_testing.h
index 5d044374044dea7..6982778ce751a47 100644
--- a/libcxx/test/support/asan_testing.h
+++ b/libcxx/test/support/asan_testing.h
@@ -11,26 +11,25 @@
#include "test_macros.h"
#include <vector>
+#include <string>
+#include <memory>
+#include <type_traits>
#if TEST_HAS_FEATURE(address_sanitizer)
-extern "C" int __sanitizer_verify_contiguous_container
- ( const void *beg, const void *mid, const void *end );
+extern "C" int __sanitizer_verify_contiguous_container(const void* beg, const void* mid, const void* end);
template <typename T, typename Alloc>
-TEST_CONSTEXPR bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &c )
-{
- if (TEST_IS_CONSTANT_EVALUATED)
- return true;
- if (std::is_same<Alloc, std::allocator<T> >::value && c.data() != NULL)
- return __sanitizer_verify_contiguous_container(
- c.data(), c.data() + c.size(), c.data() + c.capacity()) != 0;
+TEST_CONSTEXPR bool is_contiguous_container_asan_correct(const std::vector<T, Alloc>& c) {
+ if (TEST_IS_CONSTANT_EVALUATED)
return true;
+ if (std::is_same<Alloc, std::allocator<T> >::value && c.data() != NULL)
+ return __sanitizer_verify_contiguous_container(c.data(), c.data() + c.size(), c.data() + c.capacity()) != 0;
+ return true;
}
#else
template <typename T, typename Alloc>
-TEST_CONSTEXPR bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &)
-{
- return true;
+TEST_CONSTEXPR bool is_contiguous_container_asan_correct(const std::vector<T, Alloc>&) {
+ return true;
}
#endif // TEST_HAS_FEATURE(address_sanitizer)
@@ -56,4 +55,43 @@ TEST_CONSTEXPR bool is_double_ended_contiguous_container_asan_correct(const std:
}
#endif
+#if TEST_HAS_FEATURE(address_sanitizer)
+template <typename S>
+bool is_string_short(S const& s) {
+ // We do not have access to __is_long(), but we can check if strings
+ // buffer is inside strings memory. If strings memory contains its content,
+ // SSO is in use. To check it, we can just confirm that the beginning is in
+ // the string object memory block.
+ // &s - beginning of objects memory
+ // &s[0] - beginning of the buffer
+ // (&s+1) - end of objects memory
+ return (void*)std::addressof(s) <= (void*)std::addressof(s[0]) &&
+ (void*)std::addressof(s[0]) < (void*)(std::addressof(s) + 1);
+}
+
+template <typename ChrT, typename TraitsT, typename Alloc>
+TEST_CONSTEXPR bool is_string_asan_correct(const std::basic_string<ChrT, TraitsT, Alloc>& c) {
+ if (TEST_IS_CONSTANT_EVALUATED)
+ return true;
+ if (c.data() != NULL) {
+ if (!is_string_short(c) || _LIBCPP_SHORT_STRING_ANNOTATIONS_ALLOWED) {
+ if (std::is_same<Alloc, std::allocator<ChrT>>::value)
+ return __sanitizer_verify_contiguous_container(
+ c.data(), c.data() + c.size() + 1, c.data() + c.capacity() + 1) != 0;
+ else
+ return __sanitizer_verify_contiguous_container(
+ c.data(), c.data() + c.capacity() + 1, c.data() + c.capacity() + 1) != 0;
+ } else {
+ return __sanitizer_verify_contiguous_container(std::addressof(c), std::addressof(c) + 1, std::addressof(c) + 1) != 0;
+ }
+ }
+ return true;
+}
+#else
+# include <string>
+template <typename ChrT, typename TraitsT, typename Alloc>
+TEST_CONSTEXPR bool is_string_asan_correct(const std::basic_string<ChrT, TraitsT, Alloc>&) {
+ return true;
+}
+#endif // TEST_HAS_FEATURE(address_sanitizer)
#endif // ASAN_TESTING_H
>From 3be64ce4002ebe490f376c0a948113e7de3dee04 Mon Sep 17 00:00:00 2001
From: Advenam Tacet <advenam.tacet at trailofbits.com>
Date: Fri, 17 Nov 2023 18:06:19 +0100
Subject: [PATCH 2/3] clang-format-fix
---
.../string.capacity/clear.pass.cpp | 2 +-
.../string.capacity/reserve.pass.cpp | 2 +-
.../string.capacity/resize_size.pass.cpp | 14 ++--
.../string.capacity/resize_size_char.pass.cpp | 14 ++--
.../string.capacity/shrink_to_fit.pass.cpp | 4 +-
.../string.cons/T_size_size.pass.cpp | 30 ++++-----
.../basic.string/string.cons/alloc.pass.cpp | 30 +++++----
.../string.cons/char_assignment.pass.cpp | 2 +-
.../basic.string/string.cons/copy.pass.cpp | 4 +-
.../string.cons/copy_alloc.pass.cpp | 4 +-
.../string.cons/copy_assignment.pass.cpp | 4 +-
.../initializer_list_assignment.pass.cpp | 3 +-
.../string.cons/iter_alloc.pass.cpp | 4 +-
.../basic.string/string.cons/move.pass.cpp | 6 +-
.../string.cons/move_alloc.pass.cpp | 6 +-
.../string.cons/move_assignment.pass.cpp | 6 +-
.../string.cons/pointer_alloc.pass.cpp | 4 +-
.../string.cons/pointer_assignment.pass.cpp | 2 +-
.../string.cons/pointer_size_alloc.pass.cpp | 4 +-
.../string.cons/size_char_alloc.pass.cpp | 4 +-
.../string_view_assignment.pass.cpp | 2 +-
.../basic.string/string.cons/substr.pass.cpp | 64 +++++++++----------
.../string_append/iterator.pass.cpp | 2 +-
.../string_append/pointer.pass.cpp | 2 +-
.../string_append/pointer_size.pass.cpp | 2 +-
.../string_append/push_back.pass.cpp | 2 +-
.../string_append/size_char.pass.cpp | 2 +-
.../string_append/string.pass.cpp | 2 +-
.../string_append/string_size_size.pass.cpp | 14 ++--
.../string_assign/T_size_size.pass.cpp | 14 ++--
.../string_assign/iterator.pass.cpp | 2 +-
.../string_assign/pointer.pass.cpp | 2 +-
.../string_assign/pointer_size.pass.cpp | 2 +-
.../string_assign/size_char.pass.cpp | 2 +-
.../string_assign/string_size_size.pass.cpp | 14 ++--
.../string_copy/copy.pass.cpp | 8 +--
.../string_erase/iter.pass.cpp | 2 +-
.../string_erase/iter_iter.pass.cpp | 2 +-
.../string_erase/pop_back.pass.cpp | 2 +-
.../string_erase/size_size.pass.cpp | 20 +++---
.../string_insert/iter_char.pass.cpp | 20 +++---
.../string_insert/iter_iter_iter.pass.cpp | 2 +-
.../string_insert/iter_size_char.pass.cpp | 2 +-
.../string_insert/size_pointer.pass.cpp | 18 +++---
.../string_insert/size_pointer_size.pass.cpp | 18 +++---
.../string_insert/size_size_char.pass.cpp | 18 +++---
.../string_insert/size_string.pass.cpp | 18 +++---
.../size_string_size_size.pass.cpp | 18 +++---
.../string_op_plus_equal/char.pass.cpp | 2 +-
.../string_op_plus_equal/pointer.pass.cpp | 2 +-
.../string_op_plus_equal/string.pass.cpp | 2 +-
.../string_replace/iter_iter_string.pass.cpp | 2 +-
.../size_size_T_size_size.pass.cpp | 17 +++--
.../string_replace/size_size_pointer.pass.cpp | 24 ++++---
.../size_size_pointer_size.pass.cpp | 24 ++++---
.../size_size_size_char.pass.cpp | 24 ++++---
.../string_replace/size_size_string.pass.cpp | 24 ++++---
.../size_size_string_size_size.pass.cpp | 24 ++++---
.../size_size_string_view.pass.cpp | 24 ++++---
.../string_swap/swap.asan.pass.cpp | 2 +-
.../string_swap/swap.pass.cpp | 4 +-
.../string.special/swap.pass.cpp | 4 +-
libcxx/test/support/asan_testing.h | 3 +-
63 files changed, 285 insertions(+), 322 deletions(-)
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp
index 7c33f7b5dcca8f6..7fa5cd43b80af40 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp
@@ -21,7 +21,7 @@ template <class S>
TEST_CONSTEXPR_CXX20 void test(S s) {
s.clear();
assert(s.size() == 0);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
index 31b66c3fb36e753..47488906267521f 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
@@ -34,7 +34,7 @@ void test(typename S::size_type min_cap, typename S::size_type erased_index) {
assert(s == s0);
assert(s.capacity() <= old_cap);
assert(s.capacity() >= s.size());
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
index 5f9c3febc9ad0cb..7cf4b7ca3b6efd6 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
@@ -20,14 +20,12 @@
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, S expected) {
-
- if (n <= s.max_size())
- {
- s.resize(n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ if (n <= s.max_size()) {
+ s.resize(n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
index 31f047c6b5fdc35..e871b58b8c3db3e 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
@@ -20,14 +20,12 @@
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, typename S::value_type c, S expected) {
-
- if (n <= s.max_size())
- {
- s.resize(n, c);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ if (n <= s.max_size()) {
+ s.resize(n, c);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp
index ac897f116565961..57f6b49eaf99451 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp
@@ -26,7 +26,7 @@ TEST_CONSTEXPR_CXX20 void test(S s) {
assert(s == s0);
assert(s.capacity() <= old_cap);
assert(s.capacity() >= s.size());
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
@@ -43,7 +43,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {
test(s);
s.assign(100, 'a');
- for(int i = 0; i < 90; ++i)
+ for (int i = 0; i < 90; ++i)
s.erase(1);
test(s);
}
diff --git a/libcxx/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp
index 5d595746f8959f2..4d46e578cefca52 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp
@@ -27,22 +27,20 @@
template <class S, class SV>
TEST_CONSTEXPR_CXX20 void test(SV sv, std::size_t pos, std::size_t n) {
-
- typedef typename S::traits_type T;
- typedef typename S::allocator_type A;
- typedef typename S::size_type Size;
- if (pos <= sv.size())
- {
- S s2(sv, static_cast<Size>(pos), static_cast<Size>(n));
- LIBCPP_ASSERT(s2.__invariants());
- assert(pos <= sv.size());
- std::size_t rlen = std::min(sv.size() - pos, n);
- assert(s2.size() == rlen);
- assert(T::compare(s2.data(), sv.data() + pos, rlen) == 0);
- assert(s2.get_allocator() == A());
- assert(s2.capacity() >= s2.size());
- LIBCPP_ASSERT(is_string_asan_correct(s2));
- }
+ typedef typename S::traits_type T;
+ typedef typename S::allocator_type A;
+ typedef typename S::size_type Size;
+ if (pos <= sv.size()) {
+ S s2(sv, static_cast<Size>(pos), static_cast<Size>(n));
+ LIBCPP_ASSERT(s2.__invariants());
+ assert(pos <= sv.size());
+ std::size_t rlen = std::min(sv.size() - pos, n);
+ assert(s2.size() == rlen);
+ assert(T::compare(s2.data(), sv.data() + pos, rlen) == 0);
+ assert(s2.get_allocator() == A());
+ assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.cons/alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/alloc.pass.cpp
index 46a2d943691526d..91beac37764db48 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/alloc.pass.cpp
@@ -33,8 +33,8 @@ TEST_CONSTEXPR_CXX20 void test() {
assert(s.capacity() >= s.size());
assert(s.get_allocator() == typename S::allocator_type());
LIBCPP_ASSERT(is_string_asan_correct(s));
- }
- {
+ }
+ {
#if TEST_STD_VER > 14
static_assert((noexcept(S{typename S::allocator_type{}})), "");
#elif TEST_STD_VER >= 11
@@ -48,8 +48,8 @@ TEST_CONSTEXPR_CXX20 void test() {
assert(s.size() == 0);
assert(s.capacity() >= s.size());
assert(s.get_allocator() == typename S::allocator_type(5));
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
}
#if TEST_STD_VER >= 11
@@ -68,22 +68,24 @@ TEST_CONSTEXPR_CXX20 void test2() {
assert(s.size() == 0);
assert(s.capacity() >= s.size());
assert(s.get_allocator() == typename S::allocator_type());
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
- {
-#if TEST_STD_VER > 14
- static_assert((noexcept(S{typename S::allocator_type{}})), "" );
-#elif TEST_STD_VER >= 11
- static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
-#endif
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
+ {
+# if TEST_STD_VER > 14
+ static_assert((noexcept(S{typename S::allocator_type{}})), "");
+# elif TEST_STD_VER >= 11
+ static_assert((noexcept(S(typename S::allocator_type())) ==
+ std::is_nothrow_copy_constructible<typename S::allocator_type>::value),
+ "");
+# endif
S s(typename S::allocator_type{});
LIBCPP_ASSERT(s.__invariants());
assert(s.data());
assert(s.size() == 0);
assert(s.capacity() >= s.size());
assert(s.get_allocator() == typename S::allocator_type());
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
}
#endif
diff --git a/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp
index c011f07840c3c6a..caf5b65a7c4878d 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp
@@ -25,7 +25,7 @@ TEST_CONSTEXPR_CXX20 void test(S s1, typename S::value_type s2) {
assert(s1.size() == 1);
assert(T::eq(s1[0], s2));
assert(s1.capacity() >= s1.size());
- LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/copy.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/copy.pass.cpp
index 607adec0587d905..f65f8e97c98249c 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/copy.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/copy.pass.cpp
@@ -25,8 +25,8 @@ TEST_CONSTEXPR_CXX20 void test(S s1) {
assert(s2 == s1);
assert(s2.capacity() >= s2.size());
assert(s2.get_allocator() == s1.get_allocator());
- LIBCPP_ASSERT(is_string_asan_correct(s1));
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
index aa8c1408e887202..ba4d4bac2995429 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
@@ -84,8 +84,8 @@ TEST_CONSTEXPR_CXX20 void test(S s1, const typename S::allocator_type& a) {
assert(s2 == s1);
assert(s2.capacity() >= s2.size());
assert(s2.get_allocator() == a);
- LIBCPP_ASSERT(is_string_asan_correct(s1));
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp
index cfc9f66b584c045..9f4213b3fd05bff 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp
@@ -24,8 +24,8 @@ TEST_CONSTEXPR_CXX20 void test(S s1, const S& s2) {
LIBCPP_ASSERT(s1.__invariants());
assert(s1 == s2);
assert(s1.capacity() >= s1.size());
- LIBCPP_ASSERT(is_string_asan_correct(s1));
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp
index 0ef13412ad2c502..af565cf18e181df 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp
@@ -49,7 +49,8 @@ TEST_CONSTEXPR_CXX20 bool test() {
{
typedef std::basic_string<char, std::char_traits<char>, safe_allocator<char>> S;
S s;
- s = {'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a'};
+ s = {'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
+ 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'};
assert(s == "aaaaaaaaaaaaaaaaaaaaaaaa");
LIBCPP_ASSERT(is_string_asan_correct(s));
}
diff --git a/libcxx/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp
index c7db45a3c80e4bd..e14227d1a77171e 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp
@@ -38,7 +38,7 @@ TEST_CONSTEXPR_CXX20 void test(It first, It last) {
}
assert(s2.get_allocator() == Alloc());
assert(s2.capacity() >= s2.size());
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc, class It>
@@ -56,7 +56,7 @@ TEST_CONSTEXPR_CXX20 void test(It first, It last, const Alloc& a) {
}
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/move.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/move.pass.cpp
index d584ea651a0bc7e..5d2d774b3606383 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/move.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/move.pass.cpp
@@ -29,9 +29,9 @@ TEST_CONSTEXPR_CXX20 void test(S s0) {
assert(s2 == s1);
assert(s2.capacity() >= s2.size());
assert(s2.get_allocator() == s1.get_allocator());
- LIBCPP_ASSERT(is_string_asan_correct(s0));
- LIBCPP_ASSERT(is_string_asan_correct(s1));
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s0));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
index cf7daf5ccf1a703..7210d67b5cb226b 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
@@ -29,9 +29,9 @@ TEST_CONSTEXPR_CXX20 void test(S s0, const typename S::allocator_type& a) {
assert(s2 == s1);
assert(s2.capacity() >= s2.size());
assert(s2.get_allocator() == a);
- LIBCPP_ASSERT(is_string_asan_correct(s0));
- LIBCPP_ASSERT(is_string_asan_correct(s1));
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s0));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
TEST_CONSTEXPR_CXX20 bool test() {
diff --git a/libcxx/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp
index 1f46b96990abe69..3e42dfcb23d437c 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp
@@ -29,9 +29,9 @@ TEST_CONSTEXPR_CXX20 void test(S s1, S s2) {
LIBCPP_ASSERT(s2.__invariants());
assert(s1 == s0);
assert(s1.capacity() >= s1.size());
- LIBCPP_ASSERT(is_string_asan_correct(s0));
- LIBCPP_ASSERT(is_string_asan_correct(s1));
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s0));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp
index 6f9eafaa25e5ded..9c3ad73bf5a4be4 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp
@@ -32,7 +32,7 @@ TEST_CONSTEXPR_CXX20 void test(const charT* s) {
assert(T::compare(s2.data(), s, n) == 0);
assert(s2.get_allocator() == Alloc());
assert(s2.capacity() >= s2.size());
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc, class charT>
@@ -46,7 +46,7 @@ TEST_CONSTEXPR_CXX20 void test(const charT* s, const Alloc& a) {
assert(T::compare(s2.data(), s, n) == 0);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp
index 742263d354a749e..d463763223c90ee 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp
@@ -26,7 +26,7 @@ TEST_CONSTEXPR_CXX20 void test(S s1, const typename S::value_type* s2) {
assert(s1.size() == T::length(s2));
assert(T::compare(s1.data(), s2, s1.size()) == 0);
assert(s1.capacity() >= s1.size());
- LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp
index bf662c05f9cef3a..9fb48b7898c74c6 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp
@@ -30,7 +30,7 @@ TEST_CONSTEXPR_CXX20 void test(const CharT* s, unsigned n) {
assert(T::compare(s2.data(), s, n) == 0);
assert(s2.get_allocator() == Alloc());
assert(s2.capacity() >= s2.size());
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc, class CharT>
@@ -43,7 +43,7 @@ TEST_CONSTEXPR_CXX20 void test(const CharT* s, unsigned n, const Alloc& a) {
assert(T::compare(s2.data(), s, n) == 0);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp
index 0e2f7ebbdafcc90..e7c90459f98e3b1 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp
@@ -31,7 +31,7 @@ TEST_CONSTEXPR_CXX20 void test(unsigned n, charT c) {
assert(s2[i] == c);
assert(s2.get_allocator() == Alloc());
assert(s2.capacity() >= s2.size());
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc, class charT>
@@ -44,7 +44,7 @@ TEST_CONSTEXPR_CXX20 void test(unsigned n, charT c, const Alloc& a) {
assert(s2[i] == c);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class Alloc, class Tp>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp
index b66124b763a1b3e..31d2c231e4cb877 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp
@@ -25,7 +25,7 @@ TEST_CONSTEXPR_CXX20 void test(S s1, SV sv) {
assert(s1.size() == sv.size());
assert(T::compare(s1.data(), sv.data(), s1.size()) == 0);
assert(s1.capacity() >= s1.size());
- LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.cons/substr.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/substr.pass.cpp
index c78651c0dfc2954..414062cc72e0407 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/substr.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/substr.pass.cpp
@@ -34,16 +34,15 @@ TEST_CONSTEXPR_CXX20 void test(S str, unsigned pos) {
typedef typename S::allocator_type A;
if (pos <= str.size()) {
-
- S s2(str, pos);
- LIBCPP_ASSERT(s2.__invariants());
- typename S::size_type rlen = str.size() - pos;
- assert(s2.size() == rlen);
- assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
- assert(s2.get_allocator() == A());
- assert(s2.capacity() >= s2.size());
- LIBCPP_ASSERT(is_string_asan_correct(s2));
- }
+ S s2(str, pos);
+ LIBCPP_ASSERT(s2.__invariants());
+ typename S::size_type rlen = str.size() - pos;
+ assert(s2.size() == rlen);
+ assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
+ assert(s2.get_allocator() == A());
+ assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
@@ -58,20 +57,18 @@ TEST_CONSTEXPR_CXX20 void test(S str, unsigned pos) {
template <class S>
TEST_CONSTEXPR_CXX20 void test(S str, unsigned pos, unsigned n) {
-
- typedef typename S::traits_type T;
- typedef typename S::allocator_type A;
- if (pos <= str.size())
- {
- S s2(str, pos, n);
- LIBCPP_ASSERT(s2.__invariants());
- typename S::size_type rlen = std::min<typename S::size_type>(str.size() - pos, n);
- assert(s2.size() == rlen);
- assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
- assert(s2.get_allocator() == A());
- assert(s2.capacity() >= s2.size());
- LIBCPP_ASSERT(is_string_asan_correct(s2));
- }
+ typedef typename S::traits_type T;
+ typedef typename S::allocator_type A;
+ if (pos <= str.size()) {
+ S s2(str, pos, n);
+ LIBCPP_ASSERT(s2.__invariants());
+ typename S::size_type rlen = std::min<typename S::size_type>(str.size() - pos, n);
+ assert(s2.size() == rlen);
+ assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
+ assert(s2.get_allocator() == A());
+ assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
@@ -89,16 +86,15 @@ TEST_CONSTEXPR_CXX20 void test(S str, unsigned pos, unsigned n, const typename S
typedef typename S::traits_type T;
if (pos <= str.size()) {
-
- S s2(str, pos, n, a);
- LIBCPP_ASSERT(s2.__invariants());
- typename S::size_type rlen = std::min<typename S::size_type>(str.size() - pos, n);
- assert(s2.size() == rlen);
- assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
- assert(s2.get_allocator() == a);
- assert(s2.capacity() >= s2.size());
- LIBCPP_ASSERT(is_string_asan_correct(s2));
- }
+ S s2(str, pos, n, a);
+ LIBCPP_ASSERT(s2.__invariants());
+ typename S::size_type rlen = std::min<typename S::size_type>(str.size() - pos, n);
+ assert(s2.size() == rlen);
+ assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
+ assert(s2.get_allocator() == a);
+ assert(s2.capacity() >= s2.size());
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
index 115dbc003b5e0fe..0f5d6510dab64fe 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
@@ -24,7 +24,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, It first, It last, S expected) {
s.append(first, last);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
#ifndef TEST_HAS_NO_EXCEPTIONS
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
index 97ca09adc56bd42..31501371da20cb9 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
@@ -23,7 +23,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, S expecte
s.append(str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
index 7efbc4cdf41f6f7..d28c3ae413dd79a 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
@@ -24,7 +24,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, typename
s.append(str, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp
index 233cafffa6981f6..aaa73cdf2fd6d3b 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp
@@ -62,7 +62,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, typename S::value_type c, S expected) {
s.push_back(c);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp
index 8a01ec34a189e2d..a068cf9a45ebfb1 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp
@@ -23,7 +23,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, typename S::value_t
s.append(n, c);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp
index 3cc5627e18857f3..b105d092ee4acea 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp
@@ -23,7 +23,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, S str, S expected) {
s.append(str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
index d4991dc2caa4602..9041053c563b098 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
@@ -22,14 +22,12 @@
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected) {
-
- if (pos <= str.size())
- {
- s.append(str, pos, n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ if (pos <= str.size()) {
+ s.append(str, pos, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
index 0f38571d521e3ae..e0630fd83055f72 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
@@ -21,14 +21,12 @@
template <class S, class SV>
TEST_CONSTEXPR_CXX20 void test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected) {
-
- if (pos <= sv.size())
- {
- s.assign(sv, pos, n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ if (pos <= sv.size()) {
+ s.assign(sv, pos, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
index 22238bf52a05718..fb9be47c1489584 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
@@ -24,7 +24,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, It first, It last, S expected) {
s.assign(first, last);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
#ifndef TEST_HAS_NO_EXCEPTIONS
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
index 1f97c72e13a6866..a26e5e947a9200e 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
@@ -23,7 +23,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, S expecte
s.assign(str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
index 53435be2ef9dafd..445a1629ef3cfc5 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
@@ -24,7 +24,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, typename
s.assign(str, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp
index 1b3a4c41fb710ee..9368839d5855268 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp
@@ -23,7 +23,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, typename S::value_t
s.assign(n, c);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
index be9bdaa473e7dd8..5846ca9d7da0363 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
@@ -22,14 +22,12 @@
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected) {
-
- if (pos <= str.size())
- {
- s.assign(str, pos, n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ if (pos <= str.size()) {
+ s.assign(str, pos, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
index ceb0d4d44410e6b..10719dab61df09d 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
@@ -27,11 +27,11 @@ TEST_CONSTEXPR_CXX20 void test(S str, typename S::value_type* s, typename S::siz
typename S::size_type rlen = std::min(n, cs.size() - pos);
assert(r == rlen);
LIBCPP_ASSERT(is_string_asan_correct(str));
- LIBCPP_ASSERT(is_string_asan_correct(cs));
+ LIBCPP_ASSERT(is_string_asan_correct(cs));
- for (r = 0; r < rlen; ++r)
- assert(S::traits_type::eq(cs[pos+r], s[r]));
- }
+ for (r = 0; r < rlen; ++r)
+ assert(S::traits_type::eq(cs[pos + r], s[r]));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp
index b79a8c3606b67b0..cb94bfe3ca4e94c 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp
@@ -25,7 +25,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, typename S::difference_type pos, S expected)
assert(s[s.size()] == typename S::value_type());
assert(s == expected);
assert(i - s.begin() == pos);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp
index 125be1bf262fea8..b0b97ce6cdf87cf 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp
@@ -26,7 +26,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, typename S::difference_type pos, typename S:
assert(s[s.size()] == typename S::value_type());
assert(s == expected);
assert(i - s.begin() == pos);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp
index ba717ac8a7bc1e2..7fc715f9d21daa6 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp
@@ -23,7 +23,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, S expected) {
LIBCPP_ASSERT(s.__invariants());
assert(s[s.size()] == typename S::value_type());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
index 8d785ea783856ea..20b181449c152b0 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
@@ -21,17 +21,15 @@
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos, typename S::size_type n, S expected) {
-
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size)
- {
- s.erase(pos, n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s[s.size()] == typename S::value_type());
- assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size) {
+ s.erase(pos, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s[s.size()] == typename S::value_type());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp
index 39fc648b95f3924..f13e0ee37d2651a 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp
@@ -21,16 +21,16 @@
template <class S>
TEST_CONSTEXPR_CXX20 void test(S& s, typename S::const_iterator p, typename S::value_type c, S expected) {
LIBCPP_ASSERT(is_string_asan_correct(s));
- bool sufficient_cap = s.size() < s.capacity();
- typename S::difference_type pos = p - s.begin();
- typename S::iterator i = s.insert(p, c);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- assert(i - s.begin() == pos);
- assert(*i == c);
- if (sufficient_cap)
- assert(i == p);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ bool sufficient_cap = s.size() < s.capacity();
+ typename S::difference_type pos = p - s.begin();
+ typename S::iterator i = s.insert(p, c);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ assert(i - s.begin() == pos);
+ assert(*i == c);
+ if (sufficient_cap)
+ assert(i == p);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
index 96b8c1e3b74e2a7..ee3adaa06ec4e57 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
@@ -26,7 +26,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, typename S::difference_type pos, It first, I
LIBCPP_ASSERT(s.__invariants());
assert(i - s.begin() == pos);
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
#ifndef TEST_HAS_NO_EXCEPTIONS
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp
index aeaf898e5330dcd..c38efbb270a6ed9 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp
@@ -25,7 +25,7 @@ test(S s, typename S::difference_type pos, typename S::size_type n, typename S::
LIBCPP_ASSERT(s.__invariants());
assert(i - s.begin() == pos);
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
index ec436f223b739f0..a6414c06fd15f43 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
@@ -21,16 +21,14 @@
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos, const typename S::value_type* str, S expected) {
-
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size)
- {
- s.insert(pos, str);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size) {
+ s.insert(pos, str);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
index 8071499190d1b34..b9873c2522daa95 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
@@ -22,16 +22,14 @@
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, const typename S::value_type* str, typename S::size_type n, S expected) {
-
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size)
- {
- s.insert(pos, str, n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size) {
+ s.insert(pos, str, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
index 73b5e815d0dab09..b9778253496c4bc 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
@@ -22,16 +22,14 @@
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, typename S::size_type n, typename S::value_type str, S expected) {
-
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size)
- {
- s.insert(pos, n, str);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size) {
+ s.insert(pos, n, str);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
index 8a596d9fc93e994..f8c594624717dd5 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
@@ -21,16 +21,14 @@
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos, S str, S expected) {
-
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size)
- {
- s.insert(pos, str);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size) {
+ s.insert(pos, str);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
index 0e97da338cd4dca..16fc05741dfc1b0 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
@@ -24,16 +24,14 @@
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos1, S str, typename S::size_type pos2, typename S::size_type n, S expected) {
-
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos1 <= old_size && pos2 <= str.size())
- {
- s.insert(pos1, str, pos2, n);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos1 <= old_size && pos2 <= str.size()) {
+ s.insert(pos1, str, pos2, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/char.pass.cpp
index cdf0b3538f3f90b..3a76b3c0b953540 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/char.pass.cpp
@@ -22,7 +22,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, typename S::value_type str, S expected) {
s += str;
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp
index 4a77cc594cd9147..8d2dbba013eaf85 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp
@@ -22,7 +22,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, S expecte
s += str;
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp
index 62a9cf606e26e72..12060417f93c629 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp
@@ -23,7 +23,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, S str, S expected) {
s += str;
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp
index 28a90b247c3c6d9..eb0c62a66504ce6 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp
@@ -30,7 +30,7 @@ TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos1, typename S::size
assert(s == expected);
typename S::size_type rlen = str.size();
assert(s.size() == old_size - xlen + rlen);
- LIBCPP_ASSERT(is_string_asan_correct(s));
+ LIBCPP_ASSERT(is_string_asan_correct(s));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
index 58faf49e3b2033d..345ee87670636b0 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
@@ -44,15 +44,14 @@ test(S s,
const SizeT old_size = s.size();
S s0 = s;
if (pos1 <= old_size && pos2 <= sv.size()) {
-
- s.replace(pos1, n1, sv, pos2, n2);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- SizeT xlen = std::min<SizeT>(n1, old_size - pos1);
- SizeT rlen = std::min<SizeT>(n2, sv.size() - pos2);
- assert(s.size() == old_size - xlen + rlen);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ s.replace(pos1, n1, sv, pos2, n2);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ SizeT xlen = std::min<SizeT>(n1, old_size - pos1);
+ SizeT rlen = std::min<SizeT>(n2, sv.size() - pos2);
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
index c425c4984e66ab6..aefe3ced9765ef1 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
@@ -23,19 +23,17 @@
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, typename S::size_type n1, const typename S::value_type* str, S expected) {
-
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size)
- {
- s.replace(pos, n1, str);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- typename S::size_type xlen = std::min(n1, old_size - pos);
- typename S::size_type rlen = S::traits_type::length(str);
- assert(s.size() == old_size - xlen + rlen);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size) {
+ s.replace(pos, n1, str);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type xlen = std::min(n1, old_size - pos);
+ typename S::size_type rlen = S::traits_type::length(str);
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
index b854fa9bd50470e..cb01c34e43d4aa1 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
@@ -28,19 +28,17 @@ test(S s,
const typename S::value_type* str,
typename S::size_type n2,
S expected) {
-
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size)
- {
- s.replace(pos, n1, str, n2);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- typename S::size_type xlen = std::min(n1, old_size - pos);
- typename S::size_type rlen = n2;
- assert(s.size() == old_size - xlen + rlen);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size) {
+ s.replace(pos, n1, str, n2);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type xlen = std::min(n1, old_size - pos);
+ typename S::size_type rlen = n2;
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
index 067826cd3fc36d9..80fa1e76f245c5c 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
@@ -28,19 +28,17 @@ test(S s,
typename S::size_type n2,
typename S::value_type c,
S expected) {
-
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos <= old_size)
- {
- s.replace(pos, n1, n2, c);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- typename S::size_type xlen = std::min(n1, old_size - pos);
- typename S::size_type rlen = n2;
- assert(s.size() == old_size - xlen + rlen);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size) {
+ s.replace(pos, n1, n2, c);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type xlen = std::min(n1, old_size - pos);
+ typename S::size_type rlen = n2;
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
index a56313ca09396a2..86cab0dd7ca16ea 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
@@ -22,19 +22,17 @@
template <class S>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos1, typename S::size_type n1, S str, S expected) {
-
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos1 <= old_size)
- {
- s.replace(pos1, n1, str);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- typename S::size_type xlen = std::min(n1, old_size - pos1);
- typename S::size_type rlen = str.size();
- assert(s.size() == old_size - xlen + rlen);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos1 <= old_size) {
+ s.replace(pos1, n1, str);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type xlen = std::min(n1, old_size - pos1);
+ typename S::size_type rlen = str.size();
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
index 972213155180994..de02a089587926b 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
@@ -33,19 +33,17 @@ test(S s,
typename S::size_type pos2,
typename S::size_type n2,
S expected) {
-
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos1 <= old_size && pos2 <= str.size())
- {
- s.replace(pos1, n1, str, pos2, n2);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- typename S::size_type xlen = std::min(n1, old_size - pos1);
- typename S::size_type rlen = std::min(n2, str.size() - pos2);
- assert(s.size() == old_size - xlen + rlen);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos1 <= old_size && pos2 <= str.size()) {
+ s.replace(pos1, n1, str, pos2, n2);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type xlen = std::min(n1, old_size - pos1);
+ typename S::size_type rlen = std::min(n2, str.size() - pos2);
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_view.pass.cpp
index 316bb01db43d36e..485db7304bc9178 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_view.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_view.pass.cpp
@@ -22,19 +22,17 @@
template <class S, class SV>
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos1, typename S::size_type n1, SV sv, S expected) {
-
- const typename S::size_type old_size = s.size();
- S s0 = s;
- if (pos1 <= old_size)
- {
- s.replace(pos1, n1, sv);
- LIBCPP_ASSERT(s.__invariants());
- assert(s == expected);
- typename S::size_type xlen = std::min(n1, old_size - pos1);
- typename S::size_type rlen = sv.size();
- assert(s.size() == old_size - xlen + rlen);
- LIBCPP_ASSERT(is_string_asan_correct(s));
- }
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos1 <= old_size) {
+ s.replace(pos1, n1, sv);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type xlen = std::min(n1, old_size - pos1);
+ typename S::size_type rlen = sv.size();
+ assert(s.size() == old_size - xlen + rlen);
+ LIBCPP_ASSERT(is_string_asan_correct(s));
+ }
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.asan.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.asan.pass.cpp
index 3cabb3b797733f3..0c6c26a5d1c0f63 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.asan.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.asan.pass.cpp
@@ -87,7 +87,7 @@ int main(int, char**) {
test<CharT>(u'x');
}
{
- using CharT = char32_t ;
+ using CharT = char32_t;
test<CharT>(U'x');
}
#endif
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.pass.cpp
index dd5bc2eea57ce02..9750fe7fa1e3da8 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.pass.cpp
@@ -28,8 +28,8 @@ TEST_CONSTEXPR_CXX20 void test(S s1, S s2) {
LIBCPP_ASSERT(s2.__invariants());
assert(s1 == s2_);
assert(s2 == s1_);
- LIBCPP_ASSERT(is_string_asan_correct(s1));
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class S>
diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string.special/swap.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string.special/swap.pass.cpp
index 2d2c770b259294f..34f71f0abdd8989 100644
--- a/libcxx/test/std/strings/basic.string/string.nonmembers/string.special/swap.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string.special/swap.pass.cpp
@@ -30,8 +30,8 @@ TEST_CONSTEXPR_CXX20 void test(S s1, S s2) {
LIBCPP_ASSERT(s2.__invariants());
assert(s1 == s2_);
assert(s2 == s1_);
- LIBCPP_ASSERT(is_string_asan_correct(s1));
- LIBCPP_ASSERT(is_string_asan_correct(s2));
+ LIBCPP_ASSERT(is_string_asan_correct(s1));
+ LIBCPP_ASSERT(is_string_asan_correct(s2));
}
template <class S>
diff --git a/libcxx/test/support/asan_testing.h b/libcxx/test/support/asan_testing.h
index 6982778ce751a47..aaddff0879d6c98 100644
--- a/libcxx/test/support/asan_testing.h
+++ b/libcxx/test/support/asan_testing.h
@@ -82,7 +82,8 @@ TEST_CONSTEXPR bool is_string_asan_correct(const std::basic_string<ChrT, TraitsT
return __sanitizer_verify_contiguous_container(
c.data(), c.data() + c.capacity() + 1, c.data() + c.capacity() + 1) != 0;
} else {
- return __sanitizer_verify_contiguous_container(std::addressof(c), std::addressof(c) + 1, std::addressof(c) + 1) != 0;
+ return __sanitizer_verify_contiguous_container(std::addressof(c), std::addressof(c) + 1, std::addressof(c) + 1) !=
+ 0;
}
}
return true;
>From 6770f7abc2746178bf6e06ba3a1dc4c594220e5c Mon Sep 17 00:00:00 2001
From: Advenam Tacet <advenam.tacet at trailofbits.com>
Date: Thu, 23 Nov 2023 04:13:41 +0400
Subject: [PATCH 3/3] Add missing annotation
This commit adds missing annotation to the new version of `__grow_by`.
This should fix failing CI.
This annotation was somehow lost during rebasing.
---
libcxx/include/string | 1 +
1 file changed, 1 insertion(+)
diff --git a/libcxx/include/string b/libcxx/include/string
index 9362b1bcd16fa19..da90cb6de1fe788 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -2481,6 +2481,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by_without_replace(
__grow_by(__old_cap, __delta_cap, __old_sz, __n_copy, __n_del, __n_add);
_LIBCPP_SUPPRESS_DEPRECATED_POP
__set_long_size(__old_sz - __n_del + __n_add);
+ __annotate_new(__old_sz - __n_del + __n_add);
}
// assign
More information about the libcxx-commits
mailing list