brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 8545065 Raw
29 lines · plain
1// RUN: %check_clang_tidy %s bugprone-no-escape %t -- -- -Wno-int-conversion2// RUN: %check_clang_tidy %s -assume-filename=bugprone-no-escape.c bugprone-no-escape %t -- -- -fblocks -Wno-int-conversion3 4typedef struct dispatch_queue_s *dispatch_queue_t;5typedef struct dispatch_time_s *dispatch_time_t;6typedef void (^dispatch_block_t)(void);7void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);8void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);9 10extern dispatch_queue_t queue;11 12void test_noescape_attribute(__attribute__((noescape)) int *p, int *q) {13  dispatch_async(queue, ^{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(456, queue, ^{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, ^{25    *q = 0;26    // CHECK-MESSAGES-NOT: :[[@LINE-2]]:25: warning: pointer 'q' with attribute 'noescape' is captured by an asynchronously-executed block27  });28}29