@@ -659,6 +659,7 @@ _LIBCPP_PUSH_MACROS
659659#else
660660# define _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
661661#endif
662+ #define _LIBCPP_SHORT_STRING_ANNOTATIONS_ALLOWED false
662663
663664_LIBCPP_BEGIN_NAMESPACE_STD
664665
@@ -1895,33 +1896,38 @@ private:
18951896#endif
18961897 }
18971898
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+
18981904 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_new (size_type __current_size) const _NOEXCEPT {
18991905 (void ) __current_size;
19001906#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 ()) )
19021908 __annotate_contiguous_container (data () + capacity () + 1 , data () + __current_size + 1 );
19031909#endif
19041910 }
19051911
19061912 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_delete () const _NOEXCEPT {
19071913#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 ()) )
19091915 __annotate_contiguous_container (data () + size () + 1 , data () + capacity () + 1 );
19101916#endif
19111917 }
19121918
19131919 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_increase (size_type __n) const _NOEXCEPT {
19141920 (void ) __n;
19151921#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 ()) )
19171923 __annotate_contiguous_container (data () + size () + 1 , data () + size () + 1 + __n);
19181924#endif
19191925 }
19201926
19211927 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_shrink (size_type __old_size) const _NOEXCEPT {
19221928 (void ) __old_size;
19231929#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 ()) )
19251931 __annotate_contiguous_container (data () + __old_size + 1 , data () + size () + 1 );
19261932#endif
19271933 }
0 commit comments