Skip to content

Commit

Permalink
Revert "*: fix asan false positive case (pingcap#5742)"
Browse files Browse the repository at this point in the history
This reverts commit 0410d3f.
  • Loading branch information
solotzg committed Sep 19, 2022
1 parent 5b78864 commit 614c2d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
15 changes: 4 additions & 11 deletions libs/libcommon/include/common/avx2_strstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

#include <common/avx2_mem_utils.h>

#include <cassert>
#include <cstddef>
#include <cstdint>

namespace mem_utils::details
{

Expand Down Expand Up @@ -131,9 +135,6 @@ ALWAYS_INLINE static inline const char * avx2_strstr_impl(const char * src, cons
// align to 32
src = reinterpret_cast<decltype(src)>(ALIGNED_ADDR(size_t(src), BLOCK32_SIZE));

// load block 32 from new aligned address may cause false positives when using `AddressSanitizer` because asan will provide a malloc()/free() alternative and detect memory visitation.
// generally it's safe to visit address which won't cross page boundary.

// right shift offset to remove useless mask bit
auto mask = get_block32_cmp_eq_mask(src, check_block32) >> offset;

Expand Down Expand Up @@ -250,10 +251,6 @@ ALWAYS_INLINE static inline const char * avx2_strstr_impl(const char * src, size

ALWAYS_INLINE static inline size_t avx2_strstr(const char * src, size_t n, const char * needle, size_t k)
{
#if defined(ADDRESS_SANITIZER)
return std::string_view{src, n}.find({needle, k}); // memchr@plt -> bcmp@plt
#endif

const auto * p = avx2_strstr_impl(src, n, needle, k);
return p ? p - src : std::string_view::npos;
}
Expand All @@ -263,10 +260,6 @@ ALWAYS_INLINE static inline size_t avx2_strstr(std::string_view src, std::string
}
ALWAYS_INLINE static inline const char * avx2_memchr(const char * src, size_t n, char target)
{
#if defined(ADDRESS_SANITIZER)
return static_cast<const char *>(std::memchr(src, target, n)); // memchr@plt
#endif

if (unlikely(n < 1))
{
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion libs/libcommon/include/common/mem_utils_opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ FLATTEN_INLINE_PURE static inline int CompareStrView(const std::string_view & lh
#endif
}

// same function like `std::string_view::find(std::string_view)`
// same function like `std::string_view::find`
FLATTEN_INLINE_PURE static inline size_t StrFind(std::string_view src, std::string_view needle)
{
#ifdef TIFLASH_ENABLE_AVX_SUPPORT
Expand Down

0 comments on commit 614c2d5

Please sign in to comment.