@@ -659,6 +659,7 @@ _LIBCPP_PUSH_MACROS
659
659
#else
660
660
# define _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
661
661
#endif
662
+ #define _LIBCPP_SHORT_STRING_ANNOTATIONS_ALLOWED false
662
663
663
664
_LIBCPP_BEGIN_NAMESPACE_STD
664
665
@@ -1895,33 +1896,38 @@ private:
1895
1896
#endif
1896
1897
}
1897
1898
1899
+ // ASan: short string is poisoned if and only if this function returns true.
1900
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __asan_short_string_is_annotated () const _NOEXCEPT {
1901
+ return _LIBCPP_SHORT_STRING_ANNOTATIONS_ALLOWED && !__libcpp_is_constant_evaluated ();
1902
+ }
1903
+
1898
1904
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_new (size_type __current_size) const _NOEXCEPT {
1899
1905
(void ) __current_size;
1900
1906
#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
1901
- if (!__libcpp_is_constant_evaluated ())
1907
+ if (!__libcpp_is_constant_evaluated () && ( __asan_short_string_is_annotated () || __is_long ()) )
1902
1908
__annotate_contiguous_container (data () + capacity () + 1 , data () + __current_size + 1 );
1903
1909
#endif
1904
1910
}
1905
1911
1906
1912
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_delete () const _NOEXCEPT {
1907
1913
#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
1908
- if (!__libcpp_is_constant_evaluated ())
1914
+ if (!__libcpp_is_constant_evaluated () && ( __asan_short_string_is_annotated () || __is_long ()) )
1909
1915
__annotate_contiguous_container (data () + size () + 1 , data () + capacity () + 1 );
1910
1916
#endif
1911
1917
}
1912
1918
1913
1919
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_increase (size_type __n) const _NOEXCEPT {
1914
1920
(void ) __n;
1915
1921
#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
1916
- if (!__libcpp_is_constant_evaluated ())
1922
+ if (!__libcpp_is_constant_evaluated () && ( __asan_short_string_is_annotated () || __is_long ()) )
1917
1923
__annotate_contiguous_container (data () + size () + 1 , data () + size () + 1 + __n);
1918
1924
#endif
1919
1925
}
1920
1926
1921
1927
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_shrink (size_type __old_size) const _NOEXCEPT {
1922
1928
(void ) __old_size;
1923
1929
#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
1924
- if (!__libcpp_is_constant_evaluated ())
1930
+ if (!__libcpp_is_constant_evaluated () && ( __asan_short_string_is_annotated () || __is_long ()) )
1925
1931
__annotate_contiguous_container (data () + __old_size + 1 , data () + size () + 1 );
1926
1932
#endif
1927
1933
}
0 commit comments