Skip to content

Conversation

DanBlackwell
Copy link
Contributor

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

…ol 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
@llvmbot
Copy link
Member

llvmbot commented Sep 29, 2025

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

Author: Dan Blackwell (DanBlackwell)

Changes

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 --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);

@DanBlackwell DanBlackwell merged commit e40ff72 into llvm:main Oct 7, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants