1 // Check that dispatch_once() is always intercepted.
3 // RUN: %clang_tsan %s -o %t
4 // RUN: not %env_tsan_opts=ignore_noninstrumented_modules=0 %run %t 2>&1 | FileCheck %s
6 #include <dispatch/dispatch.h>
16 __attribute__((disable_sanitizer_instrumentation
))
18 static dispatch_once_t onceToken
;
19 dispatch_once(&onceToken
, ^{
25 // Required for dyld macOS 12.0+
29 __attribute__((disable_sanitizer_instrumentation
))
32 fprintf(stderr
, "Report.\n");
34 // Without these annotations this test deadlocks for COMPILER_RT_DEBUG=ON
35 // builds. Conceptually, the TSan runtime does not support reentrancy from
36 // runtime callbacks, but the main goal here is just to check that
37 // dispatch_once() is always intercepted.
38 AnnotateIgnoreSyncBegin(__FILE__
, __LINE__
);
40 AnnotateIgnoreSyncEnd(__FILE__
, __LINE__
);
44 fprintf(stderr
, "Hello world.\n");
48 pthread_mutex_t mutex
= PTHREAD_MUTEX_INITIALIZER
;
49 pthread_mutex_unlock(&mutex
); // Unlock of an unlocked mutex
51 fprintf(stderr
, "g = %ld.\n", g
);
52 fprintf(stderr
, "h = %ld.\n", h
);
53 fprintf(stderr
, "Done.\n");
56 // CHECK: Hello world.