Skip to content

Commit a78b11a

Browse files
committed
[TSan][test-only] Make TSan os_unfair_lock.c test check the weak symbol before using
The os_unfair_lock.c test can currently fail with a null dereference if compiled on a platform with os_unfair_lock_lock_with_flags, but then executed on a platform without the function. This patch fixes this by first checking whether the symbol exists, and falls back to os_unfair_lock_lock if not. rdar://160596542
1 parent 3c98be4 commit a78b11a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

compiler-rt/test/tsan/Darwin/os_unfair_lock.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ void *ThreadWithFlags(void *a) {
2222
defined(__VISIONOS_2_0) || defined(__WATCHOS_11_0)
2323
# pragma clang diagnostic push
2424
# pragma clang diagnostic ignored "-Wunguarded-availability-new"
25-
os_unfair_lock_lock_with_flags(&lock, OS_UNFAIR_LOCK_FLAG_ADAPTIVE_SPIN);
26-
flags_available = 1;
25+
if (os_unfair_lock_lock_with_flags) {
26+
os_unfair_lock_lock_with_flags(&lock, OS_UNFAIR_LOCK_FLAG_ADAPTIVE_SPIN);
27+
flags_available = 1;
28+
} else {
29+
os_unfair_lock_lock(&lock);
30+
}
2731
# pragma clang diagnostic pop
2832
#else
2933
os_unfair_lock_lock(&lock);

0 commit comments

Comments
 (0)