[compiler-rt] [ASan][Darwin][GCD] Add interceptor for dispatch_apply (PR #149238)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 17 09:27:00 PDT 2025


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 HEAD~1 HEAD --extensions h,c,cpp -- compiler-rt/test/asan/TestCases/Darwin/dispatch_apply_threadno.c compiler-rt/lib/asan/asan_mac.cpp compiler-rt/lib/asan/tests/asan_mac_test.cpp compiler-rt/lib/asan/tests/asan_mac_test.h
``````````

</details>

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

``````````diff
diff --git a/compiler-rt/lib/asan/asan_mac.cpp b/compiler-rt/lib/asan/asan_mac.cpp
index 9c275fc47..c2b8a60d7 100644
--- a/compiler-rt/lib/asan/asan_mac.cpp
+++ b/compiler-rt/lib/asan/asan_mac.cpp
@@ -245,30 +245,24 @@ INTERCEPTOR(void, dispatch_group_async_f, dispatch_group_t group,
                                asan_dispatch_call_block_and_release);
 }
 
-extern "C"
-void asan_dispatch_apply_f_block(void *context, size_t iteration) {
+extern "C" void asan_dispatch_apply_f_block(void *context, size_t iteration) {
   GET_STACK_TRACE_THREAD;
   asan_block_context_t *asan_ctxt = (asan_block_context_t *)context;
   asan_register_worker_thread(asan_ctxt->parent_tid, &stack);
   ((void (*)(void *, size_t))asan_ctxt->func)(asan_ctxt->block, iteration);
 }
 
-INTERCEPTOR(void, dispatch_apply_f,
-            size_t iterations,
-            dispatch_queue_t queue,
-            void *ctxt,
-            void (*work)(void *, size_t)) {
-
+INTERCEPTOR(void, dispatch_apply_f, size_t iterations, dispatch_queue_t queue,
+            void *ctxt, void (*work)(void *, size_t)) {
   GET_STACK_TRACE_THREAD;
   asan_block_context_t *asan_ctxt =
       alloc_asan_context(ctxt, (dispatch_function_t)work, &stack);
 
-  REAL(dispatch_apply_f)(iterations, queue,
-                         (void *)asan_ctxt,
+  REAL(dispatch_apply_f)(iterations, queue, (void *)asan_ctxt,
                          asan_dispatch_apply_f_block);
 }
 
-#if !defined(MISSING_BLOCKS_SUPPORT)
+#  if !defined(MISSING_BLOCKS_SUPPORT)
 extern "C" {
 void dispatch_async(dispatch_queue_t dq, void(^work)(void));
 void dispatch_group_async(dispatch_group_t dg, dispatch_queue_t dq,
@@ -287,10 +281,10 @@ void dispatch_apply(size_t iterations, dispatch_queue_t queue,
 #define GET_ASAN_BLOCK(work) \
   void (^asan_block)(void);  \
   int parent_tid = GetCurrentTidOrInvalid(); \
-  asan_block = ^(void) { \
-    GET_STACK_TRACE_THREAD; \
-    asan_register_worker_thread(parent_tid, &stack); \
-    work(); \
+  asan_block = ^(void) {                     \
+        GET_STACK_TRACE_THREAD;                          \
+        asan_register_worker_thread(parent_tid, &stack); \
+        work(); \
   }
 
 INTERCEPTOR(void, dispatch_async,
diff --git a/compiler-rt/test/asan/TestCases/Darwin/dispatch_apply_threadno.c b/compiler-rt/test/asan/TestCases/Darwin/dispatch_apply_threadno.c
index c58792e11..49c0bd40c 100644
--- a/compiler-rt/test/asan/TestCases/Darwin/dispatch_apply_threadno.c
+++ b/compiler-rt/test/asan/TestCases/Darwin/dispatch_apply_threadno.c
@@ -32,7 +32,7 @@ void da_func(void *ctx, size_t i) {
 __attribute__((noinline)) void test_dispatch_apply_f() {
   Context *ctx = (Context *)malloc(sizeof(Context));
   ctx->data = (char *)malloc(4);
-  dispatch_apply_f(8, dispatch_get_global_queue(0,0), ctx, da_func);
+  dispatch_apply_f(8, dispatch_get_global_queue(0, 0), ctx, da_func);
 }
 
 int main(int argc, const char *argv[]) {

``````````

</details>


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


More information about the llvm-commits mailing list