Skip to content

Commit ab9f7c2

Browse files
committed
[libcxx] Align allocation to __set_long_cap and __get_long_cap match
This is detected by asan after llvm#83774 New assert already fails a lot of tests even without asan.
1 parent 4ad107b commit ab9f7c2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

libcxx/include/string

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ private:
868868
__r_.first() = __rep();
869869
__set_short_size(__size);
870870
} else {
871-
auto __capacity = __recommend(__size) + 1;
871+
auto __capacity = __align_it<__endian_factor>(__recommend(__size) + 1);
872872
auto __allocation = __alloc_traits::allocate(__alloc(), __capacity);
873873
__begin_lifetime(__allocation, __capacity);
874874
__set_long_cap(__capacity);
@@ -2202,7 +2202,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_ty
22022202
__set_short_size(__sz);
22032203
__p = __get_short_pointer();
22042204
} else {
2205-
auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__reserve) + 1);
2205+
auto __allocation = std::__allocate_at_least(__alloc(), __align_it<__endian_factor>(__recommend(__reserve) + 1));
22062206
__p = __allocation.ptr;
22072207
__begin_lifetime(__p, __allocation.count);
22082208
__set_long_pointer(__p);
@@ -2226,7 +2226,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_ty
22262226
__set_short_size(__sz);
22272227
__p = __get_short_pointer();
22282228
} else {
2229-
auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
2229+
auto __allocation = std::__allocate_at_least(__alloc(), __align_it<__endian_factor>(__recommend(__sz) + 1));
22302230
__p = __allocation.ptr;
22312231
__begin_lifetime(__p, __allocation.count);
22322232
__set_long_pointer(__p);
@@ -2251,7 +2251,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(const value
22512251
} else {
22522252
if (__sz > max_size())
22532253
__throw_length_error();
2254-
auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
2254+
auto __allocation = std::__allocate_at_least(__alloc(), __align_it<__endian_factor>(__recommend(__sz) + 1));
22552255
__p = __allocation.ptr;
22562256
__begin_lifetime(__p, __allocation.count);
22572257
__set_long_pointer(__p);
@@ -2274,7 +2274,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
22742274
__set_short_size(__n);
22752275
__p = __get_short_pointer();
22762276
} else {
2277-
auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__n) + 1);
2277+
auto __allocation = std::__allocate_at_least(__alloc(), __align_it<__endian_factor>(__recommend(__n) + 1));
22782278
__p = __allocation.ptr;
22792279
__begin_lifetime(__p, __allocation.count);
22802280
__set_long_pointer(__p);
@@ -2339,7 +2339,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init_with_size(_InputIterator __fir
23392339
__p = __get_short_pointer();
23402340

23412341
} else {
2342-
auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
2342+
auto __allocation = std::__allocate_at_least(__alloc(), __align_it<__endian_factor>(__recommend(__sz) + 1));
23432343
__p = __allocation.ptr;
23442344
__begin_lifetime(__p, __allocation.count);
23452345
__set_long_pointer(__p);
@@ -2379,7 +2379,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
23792379
size_type __cap =
23802380
__old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1;
23812381
__annotate_delete();
2382-
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
2382+
auto __allocation = std::__allocate_at_least(__alloc(), __align_it<__endian_factor>(__cap + 1));
23832383
pointer __p = __allocation.ptr;
23842384
__begin_lifetime(__p, __allocation.count);
23852385
if (__n_copy != 0)
@@ -2422,7 +2422,7 @@ void _LIBCPP_CONSTEXPR_SINCE_CXX20
24222422
size_type __cap =
24232423
__old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1;
24242424
__annotate_delete();
2425-
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
2425+
auto __allocation = std::__allocate_at_least(__alloc(), __align_it<__endian_factor>(__cap + 1));
24262426
pointer __p = __allocation.ptr;
24272427
__begin_lifetime(__p, __allocation.count);
24282428
if (__n_copy != 0)
@@ -3255,14 +3255,14 @@ basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target
32553255
__p = __get_long_pointer();
32563256
} else {
32573257
if (__target_capacity > __cap) {
3258-
auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1);
3258+
auto __allocation = std::__allocate_at_least(__alloc(), __align_it<__endian_factor>(__target_capacity + 1));
32593259
__new_data = __allocation.ptr;
32603260
__target_capacity = __allocation.count - 1;
32613261
} else {
32623262
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
32633263
try {
32643264
#endif // _LIBCPP_HAS_NO_EXCEPTIONS
3265-
auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1);
3265+
auto __allocation = std::__allocate_at_least(__alloc(), __align_it<__endian_factor>(__target_capacity + 1));
32663266
__new_data = __allocation.ptr;
32673267
__target_capacity = __allocation.count - 1;
32683268
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS

0 commit comments

Comments
 (0)