[compiler-rt] [TSan] Add interceptor for os_unfair_lock_lock_with_flags (PR #153815)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 15 07:47:05 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,c -- compiler-rt/lib/tsan/rtl/tsan_interceptors_mac.cpp compiler-rt/test/tsan/Darwin/os_unfair_lock.c
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_mac.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_mac.cpp
index 91567ac55..7ab232ba0 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_mac.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_mac.cpp
@@ -282,9 +282,9 @@ TSAN_INTERCEPTOR(void, os_unfair_lock_lock, os_unfair_lock_t lock) {
}
// os_unfair_lock_lock_with_flags was introduced in macOS 15
-#if defined(__MAC_15_0)
-# pragma clang diagnostic push
-# pragma clang diagnostic ignored "-Wunguarded-availability-new"
+# if defined(__MAC_15_0)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wunguarded-availability-new"
// We're just intercepting this - if it doesn't exist on the platform, then the
// process shouldn't have called it in the first place.
TSAN_INTERCEPTOR(void, os_unfair_lock_lock_with_flags, os_unfair_lock_t lock,
@@ -296,8 +296,8 @@ TSAN_INTERCEPTOR(void, os_unfair_lock_lock_with_flags, os_unfair_lock_t lock,
REAL(os_unfair_lock_lock_with_flags)(lock, flags);
Acquire(thr, pc, (uptr)lock);
}
-# pragma clang diagnostic pop
-#endif
+# pragma clang diagnostic pop
+# endif
TSAN_INTERCEPTOR(void, os_unfair_lock_lock_with_options, os_unfair_lock_t lock,
u32 options) {
diff --git a/compiler-rt/test/tsan/Darwin/os_unfair_lock.c b/compiler-rt/test/tsan/Darwin/os_unfair_lock.c
index 986c37127..7b9ba4284 100644
--- a/compiler-rt/test/tsan/Darwin/os_unfair_lock.c
+++ b/compiler-rt/test/tsan/Darwin/os_unfair_lock.c
@@ -17,7 +17,8 @@ void *Thread(void *a) {
}
void *ThreadWithFlags(void *a) {
- if (__builtin_available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, watchOS 11.0, *))
+ if (__builtin_available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0,
+ watchOS 11.0, *))
os_unfair_lock_lock_with_flags(&lock, OS_UNFAIR_LOCK_FLAG_ADAPTIVE_SPIN);
else
os_unfair_lock_lock(&lock);
@@ -35,11 +36,12 @@ int main() {
pthread_join(t2, NULL);
fprintf(stderr, "global_variable = %ld\n", global_variable);
-// CHECK: global_variable = 2
+ // CHECK: global_variable = 2
void *(*func)(void *) = Thread;
char flags_available = 0;
- if (__builtin_available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, watchOS 11.0, *)) {
+ if (__builtin_available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0,
+ watchOS 11.0, *)) {
func = ThreadWithFlags;
flags_available = 1;
}
@@ -48,7 +50,8 @@ int main() {
pthread_create(&t2, NULL, func, NULL);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
- fprintf(stderr, "global_variable = %ld, os_unfair_lock_lock_with_flags %savailable\n",
+ fprintf(stderr,
+ "global_variable = %ld, os_unfair_lock_lock_with_flags %savailable\n",
global_variable, flags_available ? "" : "un");
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/153815
More information about the llvm-commits
mailing list