xref: /llvm-project/compiler-rt/test/lsan/TestCases/Darwin/dispatch_continuations.mm (revision ed2c3f46f5a74de9965c424a3a8ca99546b2c939)
1// Test that dispatch continuation memory region is scanned.
2// RUN: %clangxx_lsan %s  -o %t -framework Foundation
3// RUN: %env_lsan_opts="report_objects=1" %run %t 2>&1 && echo "" | FileCheck %s
4
5#include <dispatch/dispatch.h>
6#include <sanitizer/lsan_interface.h>
7
8int main() {
9  // Reduced from `CFRunLoopCreate`
10  dispatch_queue_t fake_rl_queue = dispatch_get_global_queue(2, 0);
11  dispatch_source_t timer =
12      dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, fake_rl_queue);
13  dispatch_source_set_event_handler(timer, ^{
14                                    });
15  dispatch_source_set_timer(timer, DISPATCH_TIME_FOREVER, DISPATCH_TIME_FOREVER,
16                            321);
17  dispatch_resume(timer);
18  __lsan_do_leak_check();
19  dispatch_source_cancel(timer);
20  dispatch_release(timer);
21  return 0;
22}
23
24// CHECK-NOT: LeakSanitizer: detected memory leaks
25