[compiler-rt] [ASan] Update meminstrinsics to use library memmove rather than internal (PR #160740)

Dan Blackwell via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 25 10:07:22 PDT 2025


https://github.com/DanBlackwell created https://github.com/llvm/llvm-project/pull/160740

Currently `memcpy` and `memset` intrinsics map through to the library implementations if ASan has been inited, whereas `memmove` always calls `internal_memmove`.

This patch changes `memmove` to use the library implementation if ASan has been inited.

>From a8652edf1ccb4fd14291879b487e12bcf05c610d Mon Sep 17 00:00:00 2001
From: Dan Blackwell <dan_blackwell at apple.com>
Date: Thu, 25 Sep 2025 17:59:53 +0100
Subject: [PATCH] [ASan] Update meminstrinsics to use library memmove rather
 than internal

Currently memcpy and memset intrinsics map through to the library implementations if ASan has been inited, whereas memmove always calls internal_memmove.

This patch changes memmove to use the library implementation if ASan has been inited.
---
 compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp | 4 +++-
 compiler-rt/lib/asan/asan_interceptors_memintrinsics.h   | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
index bdf328f892063..f52ae9ae8d17c 100644
--- a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
@@ -55,8 +55,10 @@ using namespace __asan;
     if (LIKELY(replace_intrin_cached)) {       \
       ASAN_READ_RANGE(ctx, from, size);        \
       ASAN_WRITE_RANGE(ctx, to, size);         \
+    } else if (UNLIKELY(!AsanInited())) {      \
+      return internal_memmove(to, from, size); \
     }                                          \
-    return internal_memmove(to, from, size);   \
+    return REAL(memmove)(to, from, size);      \
   } while (0)
 
 void *__asan_memcpy(void *to, const void *from, uptr size) {
diff --git a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.h b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.h
index 14727a5d665ed..ec988cff51c59 100644
--- a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.h
+++ b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.h
@@ -20,6 +20,7 @@
 
 DECLARE_REAL(void *, memcpy, void *to, const void *from, SIZE_T size)
 DECLARE_REAL(void *, memset, void *block, int c, SIZE_T size)
+DECLARE_REAL(void *, memmove, void *to, const void *from, SIZE_T size)
 
 namespace __asan {
 



More information about the llvm-commits mailing list