1 | // RUN: %check_clang_tidy %s bugprone-no-escape %t -- -- -Wno-int-conversion |
2 | // RUN: %check_clang_tidy %s -assume-filename=bugprone-no-escape.c bugprone-no-escape %t -- -- -fblocks -Wno-int-conversion |
3 | |
4 | typedef struct dispatch_queue_s *dispatch_queue_t; |
5 | typedef struct dispatch_time_s *dispatch_time_t; |
6 | typedef void (^dispatch_block_t)(void); |
7 | void dispatch_async(dispatch_queue_t queue, dispatch_block_t block); |
8 | void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block); |
9 | |
10 | extern dispatch_queue_t queue; |
11 | |
12 | void test_noescape_attribute(__attribute__((noescape)) int *p, int *q) { |
13 | dispatch_async(queue, block: ^{ |
14 | *p = 123; |
15 | // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape] |
16 | // CHECK-MESSAGES: :[[@LINE-4]]:30: note: the 'noescape' attribute is declared here. |
17 | }); |
18 | |
19 | dispatch_after(when: 456, queue, block: ^{ |
20 | *p = 789; |
21 | // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape] |
22 | }); |
23 | |
24 | dispatch_async(queue, block: ^{ |
25 | *q = 0; |
26 | // CHECK-MESSAGES-NOT: :[[@LINE-2]]:25: warning: pointer 'q' with attribute 'noescape' is captured by an asynchronously-executed block |
27 | }); |
28 | } |
29 | |