[compiler-rt] [TSan][test-only] Make TSan os_unfair_lock.c test check the weak symbol before usage (PR #161173)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 29 04:20:06 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Dan Blackwell (DanBlackwell)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/161173.diff


1 Files Affected:

- (modified) compiler-rt/test/tsan/Darwin/os_unfair_lock.c (+6-2) 


``````````diff
diff --git a/compiler-rt/test/tsan/Darwin/os_unfair_lock.c b/compiler-rt/test/tsan/Darwin/os_unfair_lock.c
index e2a491aa98d6d..883154c372c7f 100644
--- a/compiler-rt/test/tsan/Darwin/os_unfair_lock.c
+++ b/compiler-rt/test/tsan/Darwin/os_unfair_lock.c
@@ -22,8 +22,12 @@ void *ThreadWithFlags(void *a) {
     defined(__VISIONOS_2_0) || defined(__WATCHOS_11_0)
 #  pragma clang diagnostic push
 #  pragma clang diagnostic ignored "-Wunguarded-availability-new"
-  os_unfair_lock_lock_with_flags(&lock, OS_UNFAIR_LOCK_FLAG_ADAPTIVE_SPIN);
-  flags_available = 1;
+  if (os_unfair_lock_lock_with_flags) {
+    os_unfair_lock_lock_with_flags(&lock, OS_UNFAIR_LOCK_FLAG_ADAPTIVE_SPIN);
+    flags_available = 1;
+  } else {
+    os_unfair_lock_lock(&lock);
+  }
 #  pragma clang diagnostic pop
 #else
   os_unfair_lock_lock(&lock);

``````````

</details>


https://github.com/llvm/llvm-project/pull/161173


More information about the llvm-commits mailing list