@@ -622,54 +622,57 @@ private:
622
622
623
623
static _CONSTEXPR20 void _Apply_annotation(const value_type* const _First, const size_type _Capacity,
624
624
const size_type _Old_size, const size_type _New_size) noexcept {
625
+ if constexpr (!_Disable_ASan_container_annotations_for_allocator<allocator_type>) {
625
626
#if _HAS_CXX20
626
- if (_STD is_constant_evaluated()) {
627
- return;
628
- }
627
+ if (_STD is_constant_evaluated()) {
628
+ return;
629
+ }
629
630
#endif // _HAS_CXX20
630
- // Don't annotate small strings; only annotate on the heap.
631
- if (_Capacity <= _Small_string_capacity || !_Asan_string_should_annotate) {
632
- return;
633
- }
634
631
635
- // Note that `_Capacity`, `_Old_size`, and `_New_size` do not include the null terminator
636
- const void* const _End = _First + _Capacity + 1;
637
- const void* const _Old_last = _First + _Old_size + 1 ;
638
- const void* const _New_last = _First + _New_size + 1;
632
+ // Don't annotate small strings; only annotate on the heap.
633
+ if (_Capacity <= _Small_string_capacity || !_Asan_string_should_annotate) {
634
+ return ;
635
+ }
639
636
640
- constexpr bool _Large_string_always_asan_aligned =
641
- (_Container_allocation_minimum_asan_alignment<basic_string>) >= _Asan_granularity;
637
+ // Note that `_Capacity`, `_Old_size`, and `_New_size` do not include the null terminator
638
+ const void* const _End = _First + _Capacity + 1;
639
+ const void* const _Old_last = _First + _Old_size + 1;
640
+ const void* const _New_last = _First + _New_size + 1;
642
641
643
- // for the non-aligned buffer options, the buffer must always have size >= 9 bytes,
644
- // so it will always end at least one shadow memory section.
642
+ constexpr bool _Large_string_always_asan_aligned =
643
+ (_Container_allocation_minimum_asan_alignment<basic_string>) >= _Asan_granularity;
645
644
646
- _Asan_aligned_pointers _Aligned;
647
- if constexpr (_Large_string_always_asan_aligned) {
648
- _Aligned = {_First, _STD _Get_asan_aligned_after(_End)};
649
- } else {
650
- _Aligned = _STD _Get_asan_aligned_first_end(_First, _End);
651
- }
652
- const void* const _Old_fixed = _Aligned._Clamp_to_end(_Old_last);
653
- const void* const _New_fixed = _Aligned._Clamp_to_end(_New_last);
654
-
655
- // --- always aligned case ---
656
- // old state:
657
- // [_First, _Old_last) valid
658
- // [_Old_last, asan_aligned_after(_End)) poison
659
- // new state:
660
- // [_First, _New_last) valid
661
- // [_New_last, asan_aligned_after(_End)) poison
662
-
663
- // --- sometimes non-aligned case ---
664
- // old state:
665
- // [_Aligned._First, _Old_fixed) valid
666
- // [_Old_fixed, _Aligned._End) poison
667
- // [_Aligned._End, _End) valid
668
- // new state:
669
- // [_Aligned._First, _New_fixed) valid
670
- // [_New_fixed, _Aligned._End) poison
671
- // [_Aligned._End, _End) valid
672
- _CSTD __sanitizer_annotate_contiguous_container(_Aligned._First, _Aligned._End, _Old_fixed, _New_fixed);
645
+ // for the non-aligned buffer options, the buffer must always have size >= 9 bytes,
646
+ // so it will always end at least one shadow memory section.
647
+
648
+ _Asan_aligned_pointers _Aligned;
649
+ if constexpr (_Large_string_always_asan_aligned) {
650
+ _Aligned = {_First, _STD _Get_asan_aligned_after(_End)};
651
+ } else {
652
+ _Aligned = _STD _Get_asan_aligned_first_end(_First, _End);
653
+ }
654
+ const void* const _Old_fixed = _Aligned._Clamp_to_end(_Old_last);
655
+ const void* const _New_fixed = _Aligned._Clamp_to_end(_New_last);
656
+
657
+ // --- always aligned case ---
658
+ // old state:
659
+ // [_First, _Old_last) valid
660
+ // [_Old_last, asan_aligned_after(_End)) poison
661
+ // new state:
662
+ // [_First, _New_last) valid
663
+ // [_New_last, asan_aligned_after(_End)) poison
664
+
665
+ // --- sometimes non-aligned case ---
666
+ // old state:
667
+ // [_Aligned._First, _Old_fixed) valid
668
+ // [_Old_fixed, _Aligned._End) poison
669
+ // [_Aligned._End, _End) valid
670
+ // new state:
671
+ // [_Aligned._First, _New_fixed) valid
672
+ // [_New_fixed, _Aligned._End) poison
673
+ // [_Aligned._End, _End) valid
674
+ _CSTD __sanitizer_annotate_contiguous_container(_Aligned._First, _Aligned._End, _Old_fixed, _New_fixed);
675
+ }
673
676
}
674
677
675
678
#define _ASAN_STRING_REMOVE(_Str) (_Str)._Remove_annotation()
0 commit comments