[PATCH] D38141: Annotate function parameters with attribute 'noescape'

Akira Hatanaka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 09:54:33 PDT 2017


ahatanak created this revision.

I recently tried to commit a patch that adds support for 'noescape' in clang (see https://reviews.llvm.org/D32210) but reverted it because clang failed to build compiler-rt.

The build fails because the block parameters of the following functions defined in the SDKs are preceded with DISPATCH_NOESCAPE, but the declarations in tsan_libdispatch_mac.cc do not have the attribute:

- dispatch_sync
- dispatch_barrier_sync
- dispatch_once
- dispatch_apply

This patch annotates the declarations in tsan_libdispatch_mac.cc with 'noescape'.


https://reviews.llvm.org/D38141

Files:
  lib/tsan/rtl/tsan_libdispatch_mac.cc


Index: lib/tsan/rtl/tsan_libdispatch_mac.cc
===================================================================
--- lib/tsan/rtl/tsan_libdispatch_mac.cc
+++ lib/tsan/rtl/tsan_libdispatch_mac.cc
@@ -177,7 +177,8 @@
   }
 
 #define DISPATCH_INTERCEPT_SYNC_B(name, barrier)                             \
-  TSAN_INTERCEPTOR(void, name, dispatch_queue_t q, dispatch_block_t block) { \
+  TSAN_INTERCEPTOR(void, name, dispatch_queue_t q,                           \
+                   __attribute__((__noescape__)) dispatch_block_t block) {   \
     SCOPED_TSAN_INTERCEPTOR(name, q, block);                                 \
     SCOPED_TSAN_INTERCEPTOR_USER_CALLBACK_START();                           \
     dispatch_block_t heap_block = Block_copy(block);                         \
@@ -267,7 +268,7 @@
 // need to undefine the macro.
 #undef dispatch_once
 TSAN_INTERCEPTOR(void, dispatch_once, dispatch_once_t *predicate,
-                 dispatch_block_t block) {
+                 __attribute__((__noescape__)) dispatch_block_t block) {
   SCOPED_INTERCEPTOR_RAW(dispatch_once, predicate, block);
   atomic_uint32_t *a = reinterpret_cast<atomic_uint32_t *>(predicate);
   u32 v = atomic_load(a, memory_order_acquire);
@@ -477,7 +478,8 @@
 }
 
 TSAN_INTERCEPTOR(void, dispatch_apply, size_t iterations,
-                 dispatch_queue_t queue, void (^block)(size_t)) {
+                 dispatch_queue_t queue,
+                 __attribute__((__noescape__)) void (^block)(size_t)) {
   SCOPED_TSAN_INTERCEPTOR(dispatch_apply, iterations, queue, block);
 
   void *parent_to_child_sync = nullptr;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38141.116210.patch
Type: text/x-patch
Size: 1600 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170921/642254be/attachment.bin>


More information about the llvm-commits mailing list