[compiler-rt] bfef873 - msan: Support free_sized and free_aligned_sized from C23 (#144529)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 20 09:16:44 PDT 2025
Author: Justin King
Date: 2025-06-20T09:16:40-07:00
New Revision: bfef8732be1b7b3a7ba7b3ccd93d043fd044293e
URL: https://github.com/llvm/llvm-project/commit/bfef8732be1b7b3a7ba7b3ccd93d043fd044293e
DIFF: https://github.com/llvm/llvm-project/commit/bfef8732be1b7b3a7ba7b3ccd93d043fd044293e.diff
LOG: msan: Support free_sized and free_aligned_sized from C23 (#144529)
Adds support to MSan for `free_sized` and `free_aligned_sized` from C23.
Other sanitizers will be handled with their own separate PRs.
For https://github.com/llvm/llvm-project/issues/144435
Signed-off-by: Justin King <jcking at google.com>
Added:
Modified:
compiler-rt/lib/msan/msan_interceptors.cpp
compiler-rt/test/sanitizer_common/TestCases/Linux/free_aligned_sized.c
compiler-rt/test/sanitizer_common/TestCases/Linux/free_sized.c
Removed:
################################################################################
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index f94d3cb79aa00..bc28434d1d494 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -34,6 +34,7 @@
#include "sanitizer_common/sanitizer_glibc_version.h"
#include "sanitizer_common/sanitizer_libc.h"
#include "sanitizer_common/sanitizer_linux.h"
+#include "sanitizer_common/sanitizer_platform_interceptors.h"
#include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
#include "sanitizer_common/sanitizer_platform_limits_posix.h"
#include "sanitizer_common/sanitizer_stackdepot.h"
@@ -215,6 +216,35 @@ INTERCEPTOR(void, free, void *ptr) {
MsanDeallocate(&stack, ptr);
}
+#if SANITIZER_INTERCEPT_FREE_SIZED
+INTERCEPTOR(void, free_sized, void *ptr, uptr size) {
+ if (UNLIKELY(!ptr))
+ return;
+ if (DlsymAlloc::PointerIsMine(ptr))
+ return DlsymAlloc::Free(ptr);
+ GET_MALLOC_STACK_TRACE;
+ MsanDeallocate(&stack, ptr);
+}
+# define MSAN_MAYBE_INTERCEPT_FREE_SIZED INTERCEPT_FUNCTION(free_sized)
+#else
+# define MSAN_MAYBE_INTERCEPT_FREE_SIZED
+#endif
+
+#if SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED
+INTERCEPTOR(void, free_aligned_sized, void *ptr, uptr alignment, uptr size) {
+ if (UNLIKELY(!ptr))
+ return;
+ if (DlsymAlloc::PointerIsMine(ptr))
+ return DlsymAlloc::Free(ptr);
+ GET_MALLOC_STACK_TRACE;
+ MsanDeallocate(&stack, ptr);
+}
+# define MSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED \
+ INTERCEPT_FUNCTION(free_aligned_sized)
+#else
+# define MSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED
+#endif
+
#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
INTERCEPTOR(void, cfree, void *ptr) {
if (UNLIKELY(!ptr))
@@ -1775,6 +1805,8 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(realloc);
INTERCEPT_FUNCTION(reallocarray);
INTERCEPT_FUNCTION(free);
+ MSAN_MAYBE_INTERCEPT_FREE_SIZED;
+ MSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED;
MSAN_MAYBE_INTERCEPT_CFREE;
MSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE;
MSAN_MAYBE_INTERCEPT_MALLINFO;
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/free_aligned_sized.c b/compiler-rt/test/sanitizer_common/TestCases/Linux/free_aligned_sized.c
index e9cb6f20c5ead..7710c62368191 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/free_aligned_sized.c
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/free_aligned_sized.c
@@ -1,5 +1,5 @@
// RUN: %clang -std=c23 -O0 %s -o %t && %run %t
-// UNSUPPORTED: asan, hwasan, rtsan, tsan, msan, ubsan
+// UNSUPPORTED: asan, hwasan, rtsan, tsan, ubsan
#include <stddef.h>
#include <stdlib.h>
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/free_sized.c b/compiler-rt/test/sanitizer_common/TestCases/Linux/free_sized.c
index 8cdf3216e528a..9eac562fecb03 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/free_sized.c
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/free_sized.c
@@ -1,5 +1,5 @@
// RUN: %clang -std=c23 -O0 %s -o %t && %run %t
-// UNSUPPORTED: asan, hwasan, rtsan, tsan, msan, ubsan
+// UNSUPPORTED: asan, hwasan, rtsan, tsan, ubsan
#include <stddef.h>
#include <stdlib.h>
More information about the llvm-commits
mailing list