@@ -1368,7 +1368,9 @@ public:
1368
1368
_LIBCPP_HIDE_FROM_ABI constexpr void __move_assign (basic_string&& __str, size_type __pos, size_type __len) {
1369
1369
// Pilfer the allocation from __str.
1370
1370
_LIBCPP_ASSERT_INTERNAL (__alloc () == __str.__alloc (), " __move_assign called with wrong allocator" );
1371
+ #ifndef __LIBCPP_HAS_NO_ASAN
1371
1372
size_type __old_sz = __str.size ();
1373
+ #endif
1372
1374
_LIBCPP_IF_ASAN () {
1373
1375
if (!__str.__is_long ())
1374
1376
__str.__annotate_delete ();
@@ -1382,11 +1384,13 @@ public:
1382
1384
_Traits::assign (data ()[__len], value_type ());
1383
1385
1384
1386
_LIBCPP_IF_ASAN () {
1387
+ #ifndef __LIBCPP_HAS_NO_ASAN
1385
1388
if (!__is_long ()) {
1386
1389
__annotate_new (__len);
1387
1390
} else if (__old_sz > __len) {
1388
1391
__annotate_shrink (__old_sz);
1389
1392
}
1393
+ #endif
1390
1394
}
1391
1395
}
1392
1396
#endif
@@ -2091,35 +2095,43 @@ private:
2091
2095
2092
2096
// Assigns the value in __s, guaranteed to be __n < __min_cap in length.
2093
2097
inline _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_short (const value_type* __s, size_type __n) {
2098
+ #ifndef __LIBCPP_HAS_NO_ASAN
2094
2099
size_type __old_size = size ();
2095
2100
_LIBCPP_IF_ASAN () {
2096
2101
if (__n > __old_size)
2097
2102
__annotate_increase (__n - __old_size);
2098
2103
}
2104
+ #endif
2099
2105
pointer __p =
2100
2106
__is_long () ? (__set_long_size (__n), __get_long_pointer ()) : (__set_short_size (__n), __get_short_pointer ());
2101
2107
traits_type::move (std::__to_address (__p), __s, __n);
2102
2108
traits_type::assign (__p[__n], value_type ());
2109
+ #ifndef __LIBCPP_HAS_NO_ASAN
2103
2110
_LIBCPP_IF_ASAN () {
2104
2111
if (__old_size > __n)
2105
2112
__annotate_shrink (__old_size);
2106
2113
}
2114
+ #endif
2107
2115
return *this ;
2108
2116
}
2109
2117
2110
2118
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
2111
2119
__null_terminate_at (value_type* __p, size_type __newsz) {
2120
+ #ifndef __LIBCPP_HAS_NO_ASAN
2112
2121
size_type __old_size = size ();
2113
2122
_LIBCPP_IF_ASAN () {
2114
2123
if (__newsz > __old_size)
2115
2124
__annotate_increase (__newsz - __old_size);
2116
2125
}
2126
+ #endif
2117
2127
__set_size (__newsz);
2118
2128
traits_type::assign (__p[__newsz], value_type ());
2129
+ #ifndef __LIBCPP_HAS_NO_ASAN
2119
2130
_LIBCPP_IF_ASAN () {
2120
2131
if (__old_size > __newsz)
2121
2132
__annotate_shrink (__old_size);
2122
2133
}
2134
+ #endif
2123
2135
return *this ;
2124
2136
}
2125
2137
@@ -2463,19 +2475,23 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE basic_string<_CharT, _Traits, _Al
2463
2475
basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias (const value_type* __s, size_type __n) {
2464
2476
size_type __cap = __is_short ? static_cast <size_type>(__min_cap) : __get_long_cap ();
2465
2477
if (__n < __cap) {
2478
+ #ifndef __LIBCPP_HAS_NO_ASAN
2466
2479
size_type __old_size = __is_short ? __get_short_size () : __get_long_size ();
2467
2480
_LIBCPP_IF_ASAN () {
2468
2481
if (__n > __old_size)
2469
2482
__annotate_increase (__n - __old_size);
2470
2483
}
2484
+ #endif
2471
2485
pointer __p = __is_short ? __get_short_pointer () : __get_long_pointer ();
2472
2486
__is_short ? __set_short_size (__n) : __set_long_size (__n);
2473
2487
traits_type::copy (std::__to_address (__p), __s, __n);
2474
2488
traits_type::assign (__p[__n], value_type ());
2489
+ #ifndef __LIBCPP_HAS_NO_ASAN
2475
2490
_LIBCPP_IF_ASAN () {
2476
2491
if (__old_size > __n)
2477
2492
__annotate_shrink (__old_size);
2478
2493
}
2494
+ #endif
2479
2495
} else {
2480
2496
size_type __sz = __is_short ? __get_short_size () : __get_long_size ();
2481
2497
__grow_by_and_replace (__cap - 1 , __n - __cap + 1 , __sz, 0 , __sz, __n, __s);
@@ -2488,10 +2504,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE basic_string<_CharT, _Traits, _Al
2488
2504
basic_string<_CharT, _Traits, _Allocator>::__assign_external (const value_type* __s, size_type __n) {
2489
2505
size_type __cap = capacity ();
2490
2506
if (__cap >= __n) {
2491
- size_type __old_size = size ();
2492
2507
_LIBCPP_IF_ASAN () {
2493
- if (__n > __old_size )
2494
- __annotate_increase (__n - __old_size );
2508
+ if (__n > size () )
2509
+ __annotate_increase (__n - size () );
2495
2510
}
2496
2511
value_type* __p = std::__to_address (__get_pointer ());
2497
2512
traits_type::move (__p, __s, __n);
@@ -2514,14 +2529,13 @@ template <class _CharT, class _Traits, class _Allocator>
2514
2529
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
2515
2530
basic_string<_CharT, _Traits, _Allocator>::assign (size_type __n, value_type __c) {
2516
2531
size_type __cap = capacity ();
2517
- size_type __old_size = size ();
2518
2532
if (__cap < __n) {
2519
2533
size_type __sz = size ();
2520
2534
__grow_by_without_replace (__cap, __n - __cap, __sz, 0 , __sz);
2521
2535
_LIBCPP_IF_ASAN () { __annotate_increase (__n); }
2522
2536
} else _LIBCPP_IF_ASAN () {
2523
- if (__n > __old_size )
2524
- __annotate_increase (__n - __old_size );
2537
+ if (__n > size () )
2538
+ __annotate_increase (__n - size () );
2525
2539
}
2526
2540
value_type* __p = std::__to_address (__get_pointer ());
2527
2541
traits_type::assign (__p, __n, __c);
@@ -2532,11 +2546,13 @@ template <class _CharT, class _Traits, class _Allocator>
2532
2546
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
2533
2547
basic_string<_CharT, _Traits, _Allocator>::operator =(value_type __c) {
2534
2548
pointer __p;
2549
+ #ifndef _LIBCPP_HAS_NO_ASAN
2535
2550
size_type __old_size = size ();
2536
2551
_LIBCPP_IF_ASAN () {
2537
2552
if (__old_size == 0 )
2538
2553
__annotate_increase (1 );
2539
2554
}
2555
+ #endif
2540
2556
if (__is_long ()) {
2541
2557
__p = __get_long_pointer ();
2542
2558
__set_long_size (1 );
@@ -2546,10 +2562,12 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) {
2546
2562
}
2547
2563
traits_type::assign (*__p, __c);
2548
2564
traits_type::assign (*++__p, value_type ());
2565
+ #ifndef _LIBCPP_HAS_NO_ASAN
2549
2566
_LIBCPP_IF_ASAN () {
2550
2567
if (__old_size > 1 )
2551
2568
__annotate_shrink (__old_size);
2552
2569
}
2570
+ #endif
2553
2571
return *this ;
2554
2572
}
2555
2573
@@ -2560,16 +2578,20 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2560
2578
__copy_assign_alloc (__str);
2561
2579
if (!__is_long ()) {
2562
2580
if (!__str.__is_long ()) {
2581
+ #ifndef _LIBCPP_HAS_NO_ASAN
2563
2582
size_type __old_size = __get_short_size ();
2583
+ #endif
2564
2584
_LIBCPP_IF_ASAN () {
2565
2585
if (__get_short_size () < __str.__get_short_size ())
2566
2586
__annotate_increase (__str.__get_short_size () - __get_short_size ());
2567
2587
}
2568
2588
__r_.first () = __str.__r_ .first ();
2589
+ #ifndef _LIBCPP_HAS_NO_ASAN
2569
2590
_LIBCPP_IF_ASAN () {
2570
2591
if (__old_size > __get_short_size ())
2571
2592
__annotate_shrink (__old_size);
2572
2593
}
2594
+ #endif
2573
2595
} else {
2574
2596
return __assign_no_alias<true >(__str.data (), __str.size ());
2575
2597
}
@@ -2612,13 +2634,16 @@ basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, tr
2612
2634
}
2613
2635
# endif
2614
2636
}
2637
+ #ifndef _LIBCPP_HAS_NO_ASAN
2615
2638
size_type __str_old_size = __str.size ();
2639
+ #endif
2616
2640
bool __str_was_short = !__str.__is_long ();
2617
2641
2618
2642
__move_assign_alloc (__str);
2619
2643
__r_.first () = __str.__r_ .first ();
2620
2644
__str.__set_short_size (0 );
2621
2645
traits_type::assign (__str.__get_short_pointer ()[0 ], value_type ());
2646
+ #ifndef _LIBCPP_HAS_NO_ASAN
2622
2647
_LIBCPP_IF_ASAN () {
2623
2648
if (__str_was_short && this != &__str)
2624
2649
__str.__annotate_shrink (__str_old_size);
@@ -2638,6 +2663,7 @@ basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, tr
2638
2663
// If it is long string, delete was never called on original __str's buffer.
2639
2664
__annotate_new (__get_short_size ());
2640
2665
}
2666
+ #endif
2641
2667
}
2642
2668
2643
2669
#endif
@@ -2678,8 +2704,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
2678
2704
basic_string<_CharT, _Traits, _Allocator>::__assign_trivial (_Iterator __first, _Sentinel __last, size_type __n) {
2679
2705
_LIBCPP_ASSERT_INTERNAL (
2680
2706
__string_is_trivial_iterator<_Iterator>::value, " The iterator type given to `__assign_trivial` must be trivial" );
2681
-
2707
+ # ifndef _LIBCPP_HAS_NO_ASAN
2682
2708
size_type __old_size = size ();
2709
+ #endif
2683
2710
size_type __cap = capacity ();
2684
2711
if (__cap < __n) {
2685
2712
// Unlike `append` functions, if the input range points into the string itself, there is no case that the input
@@ -2692,18 +2719,20 @@ basic_string<_CharT, _Traits, _Allocator>::__assign_trivial(_Iterator __first, _
2692
2719
__grow_by_without_replace (__cap, __n - __cap, __sz, 0 , __sz);
2693
2720
_LIBCPP_IF_ASAN () { __annotate_increase (__n); }
2694
2721
} else _LIBCPP_IF_ASAN () {
2695
- if (__n > __old_size )
2696
- __annotate_increase (__n - __old_size );
2722
+ if (__n > size () )
2723
+ __annotate_increase (__n - size () );
2697
2724
}
2698
2725
pointer __p = __get_pointer ();
2699
2726
for (; __first != __last; ++__p, (void )++__first)
2700
2727
traits_type::assign (*__p, *__first);
2701
2728
traits_type::assign (*__p, value_type ());
2702
2729
__set_size (__n);
2730
+ #ifndef _LIBCPP_HAS_NO_ASAN
2703
2731
_LIBCPP_IF_ASAN () {
2704
2732
if (__n < __old_size)
2705
2733
__annotate_shrink (__old_size);
2706
2734
}
2735
+ #endif
2707
2736
}
2708
2737
2709
2738
template <class _CharT , class _Traits , class _Allocator >
@@ -3208,15 +3237,19 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocat
3208
3237
3209
3238
template <class _CharT , class _Traits , class _Allocator >
3210
3239
inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::clear () _NOEXCEPT {
3240
+ #ifndef _LIBCPP_HAS_NO_ASAN
3211
3241
size_type __old_size = size ();
3242
+ #endif
3212
3243
if (__is_long ()) {
3213
3244
traits_type::assign (*__get_long_pointer (), value_type ());
3214
3245
__set_long_size (0 );
3215
3246
} else {
3216
3247
traits_type::assign (*__get_short_pointer (), value_type ());
3217
3248
__set_short_size (0 );
3218
3249
}
3250
+ #ifndef _LIBCPP_HAS_NO_ASAN
3219
3251
_LIBCPP_IF_ASAN () { __annotate_shrink (__old_size); }
3252
+ #endif
3220
3253
}
3221
3254
3222
3255
template <class _CharT , class _Traits , class _Allocator >
0 commit comments