[libcxx-commits] [libcxx] [ASan][libc++] std::basic_string annotations (PR #72677)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Dec 5 08:08:22 PST 2023
================
@@ -56,4 +55,44 @@ TEST_CONSTEXPR bool is_double_ended_contiguous_container_asan_correct(const std:
}
#endif
+#if TEST_HAS_FEATURE(address_sanitizer)
+template <typename S>
+bool is_string_short(S const& s) {
+ // We do not have access to __is_long(), but we can check if strings
+ // buffer is inside strings memory. If strings memory contains its content,
+ // SSO is in use. To check it, we can just confirm that the beginning is in
+ // the string object memory block.
+ // &s - beginning of objects memory
+ // &s[0] - beginning of the buffer
+ // (&s+1) - end of objects memory
+ return (void*)std::addressof(s) <= (void*)std::addressof(s[0]) &&
+ (void*)std::addressof(s[0]) < (void*)(std::addressof(s) + 1);
+}
+
+template <typename ChrT, typename TraitsT, typename Alloc>
+TEST_CONSTEXPR bool is_string_asan_correct(const std::basic_string<ChrT, TraitsT, Alloc>& c) {
+ if (TEST_IS_CONSTANT_EVALUATED)
+ return true;
+ if (c.data() != NULL) {
----------------
ldionne wrote:
`data()` is supposed to never be `nullptr`.
https://github.com/llvm/llvm-project/pull/72677
More information about the libcxx-commits
mailing list