[compiler-rt] [compiler-rt][msan] intercept a subset of non standard FreeBSD's allo… (PR #81773)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 14 10:22:37 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 6cab375b4b3d33c18c5f8686105ea20458451a71 b84c87fc980f6db28ae6207887003dccfa00c294 -- compiler-rt/lib/msan/msan.h compiler-rt/lib/msan/msan_allocator.cpp compiler-rt/lib/msan/msan_interceptors.cpp compiler-rt/lib/msan/msan_new_delete.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/compiler-rt/lib/msan/msan.h b/compiler-rt/lib/msan/msan.h
index 006d35146c..8c07e03fc0 100644
--- a/compiler-rt/lib/msan/msan.h
+++ b/compiler-rt/lib/msan/msan.h
@@ -259,7 +259,8 @@ void MsanDeallocate(BufferedStackTrace *stack, void *ptr, bool zeroise);
 
 void *msan_malloc(uptr size, BufferedStackTrace *stack, bool zeroise);
 void *msan_calloc(uptr nmemb, uptr size, BufferedStackTrace *stack);
-void *msan_realloc(void *ptr, uptr size, BufferedStackTrace *stack, bool zeroise);
+void *msan_realloc(void *ptr, uptr size, BufferedStackTrace *stack,
+                   bool zeroise);
 void *msan_reallocarray(void *ptr, uptr nmemb, uptr size,
                         BufferedStackTrace *stack);
 void *msan_valloc(uptr size, BufferedStackTrace *stack);
diff --git a/compiler-rt/lib/msan/msan_allocator.cpp b/compiler-rt/lib/msan/msan_allocator.cpp
index d686a0d14e..9722e2a045 100644
--- a/compiler-rt/lib/msan/msan_allocator.cpp
+++ b/compiler-rt/lib/msan/msan_allocator.cpp
@@ -337,7 +337,8 @@ void *msan_calloc(uptr nmemb, uptr size, BufferedStackTrace *stack) {
   return SetErrnoOnNull(MsanCalloc(stack, nmemb, size));
 }
 
-void *msan_realloc(void *ptr, uptr size, BufferedStackTrace *stack, bool zeroise) {
+void *msan_realloc(void *ptr, uptr size, BufferedStackTrace *stack,
+                   bool zeroise) {
   if (!ptr)
     return SetErrnoOnNull(MsanAllocate(stack, size, sizeof(u64), zeroise));
   if (size == 0) {
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index d1ed3a8516..5200bca018 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -297,12 +297,13 @@ INTERCEPTOR(void, malloc_stats, void) {
 #if SANITIZER_FREEBSD
 
 // Is the only flag worths replicating
-#define MSAN_MALLOCX_ZERO 0x40
+#  define MSAN_MALLOCX_ZERO 0x40
 
 INTERCEPTOR(void *, mallocx, SIZE_T size, int flags) {
   bool zeroise = (flags & MSAN_MALLOCX_ZERO);
   if (DlsymAlloc::Use())
-    return zeroise ? DlsymAlloc::Allocate(size) : DlsymAlloc::Callocate(1, size);
+    return zeroise ? DlsymAlloc::Allocate(size)
+                   : DlsymAlloc::Callocate(1, size);
   GET_MALLOC_STACK_TRACE;
   return msan_malloc(size, &stack, zeroise);
 }
@@ -333,15 +334,15 @@ INTERCEPTOR(void, dallocx, void *ptr, int flags) {
   MsanDeallocate(&stack, ptr, (flags & MSAN_MALLOCX_ZERO));
 }
 
-#define MSAN_MAYBE_INTERCEPT_MALLOCX INTERCEPT_FUNCTION(mallocx)
-#define MSAN_MAYBE_INTERCEPT_RALLOCX INTERCEPT_FUNCTION(rallocx)
-#define MSAN_MAYBE_INTERCEPT_SALLOCX INTERCEPT_FUNCTION(sallocx)
-#define MSAN_MAYBE_INTERCEPT_DALLOCX INTERCEPT_FUNCTION(dallocx)
+#  define MSAN_MAYBE_INTERCEPT_MALLOCX INTERCEPT_FUNCTION(mallocx)
+#  define MSAN_MAYBE_INTERCEPT_RALLOCX INTERCEPT_FUNCTION(rallocx)
+#  define MSAN_MAYBE_INTERCEPT_SALLOCX INTERCEPT_FUNCTION(sallocx)
+#  define MSAN_MAYBE_INTERCEPT_DALLOCX INTERCEPT_FUNCTION(dallocx)
 #else
-#define MSAN_MAYBE_INTERCEPT_MALLOCX
-#define MSAN_MAYBE_INTERCEPT_RALLOCX
-#define MSAN_MAYBE_INTERCEPT_SALLOCX
-#define MSAN_MAYBE_INTERCEPT_DALLOCX
+#  define MSAN_MAYBE_INTERCEPT_MALLOCX
+#  define MSAN_MAYBE_INTERCEPT_RALLOCX
+#  define MSAN_MAYBE_INTERCEPT_SALLOCX
+#  define MSAN_MAYBE_INTERCEPT_DALLOCX
 #endif
 
 INTERCEPTOR(char *, strcpy, char *dest, const char *src) {
diff --git a/compiler-rt/lib/msan/msan_new_delete.cpp b/compiler-rt/lib/msan/msan_new_delete.cpp
index a29c166d0a..14395cbc8e 100644
--- a/compiler-rt/lib/msan/msan_new_delete.cpp
+++ b/compiler-rt/lib/msan/msan_new_delete.cpp
@@ -30,13 +30,13 @@ namespace std {
 
 
 // TODO(alekseys): throw std::bad_alloc instead of dying on OOM.
-#  define OPERATOR_NEW_BODY(nothrow)          \
-    GET_MALLOC_STACK_TRACE;                   \
-    void *res = msan_malloc(size, &stack, false);    \
-    if (!nothrow && UNLIKELY(!res)) {         \
-      GET_FATAL_STACK_TRACE_IF_EMPTY(&stack); \
-      ReportOutOfMemory(size, &stack);        \
-    }                                         \
+#  define OPERATOR_NEW_BODY(nothrow)              \
+    GET_MALLOC_STACK_TRACE;                       \
+    void *res = msan_malloc(size, &stack, false); \
+    if (!nothrow && UNLIKELY(!res)) {             \
+      GET_FATAL_STACK_TRACE_IF_EMPTY(&stack);     \
+      ReportOutOfMemory(size, &stack);            \
+    }                                             \
     return res
 #  define OPERATOR_NEW_BODY_ALIGN(nothrow)                \
     GET_MALLOC_STACK_TRACE;                               \
@@ -72,9 +72,10 @@ INTERCEPTOR_ATTRIBUTE
 void *operator new[](size_t size, std::align_val_t align, std::nothrow_t const&)
 { OPERATOR_NEW_BODY_ALIGN(true /*nothrow*/); }
 
-#define OPERATOR_DELETE_BODY \
-  GET_MALLOC_STACK_TRACE; \
-  if (ptr) MsanDeallocate(&stack, ptr, false)
+#  define OPERATOR_DELETE_BODY \
+    GET_MALLOC_STACK_TRACE;    \
+    if (ptr)                   \
+    MsanDeallocate(&stack, ptr, false)
 
 INTERCEPTOR_ATTRIBUTE
 void operator delete(void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; }

``````````

</details>


https://github.com/llvm/llvm-project/pull/81773


More information about the llvm-commits mailing list