Skip to content

Commit 40ae296

Browse files
author
Julian Lettner
committed
[TSan][libdispatch] Guard test execution on old platforms
`dispatch_async_and_wait()` was introduced in macOS 10.14. Let's forward declare it to ensure we can compile the test with older SDKs and guard execution by checking if the symbol is available. (We can't use `__builtin_available()`, because that itself requires a higher minimum deployment target.) We also need to specify the `-undefined dynamic_lookup` compiler flag. Differential Revision: https://reviews.llvm.org/D85995
1 parent 686fe29 commit 40ae296

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

compiler-rt/test/tsan/libdispatch/async_and_wait.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
// RUN: %clang_tsan %s -o %t
1+
// RUN: %clang_tsan %s -o %t -undefined dynamic_lookup
22
// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
33

44
#include "dispatch/dispatch.h"
55

66
#include <stdio.h>
77

8+
// Allow compilation with pre-macOS 10.14 (and aligned) SDKs
9+
API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0))
10+
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
11+
void dispatch_async_and_wait(dispatch_queue_t queue,
12+
DISPATCH_NOESCAPE dispatch_block_t block);
13+
814
long global;
915

1016
int main() {
17+
// Guard execution on pre-macOS 10.14 (and aligned) platforms
18+
if (dispatch_async_and_wait == NULL) {
19+
fprintf(stderr, "Done.\n");
20+
return 0;
21+
}
22+
1123
dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
1224
dispatch_semaphore_t s = dispatch_semaphore_create(0);
1325

@@ -26,6 +38,7 @@ int main() {
2638
global++;
2739

2840
fprintf(stderr, "Done.\n");
41+
return 0;
2942
}
3043

3144
// CHECK: Done.

0 commit comments

Comments
 (0)