Skip to content

[rtsan] NFC: Fix style of some interceptors not using MAYBE #118145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

cjappl
Copy link
Contributor

@cjappl cjappl commented Nov 29, 2024

There were a few interceptors that weren't using the newer MAYBE style - fixed them up for uniform style.

@llvmbot
Copy link
Member

llvmbot commented Nov 29, 2024

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

Author: Chris Apple (cjappl)

Changes

There were a few interceptors that weren't using the newer MAYBE style - fixed them up for uniform style.


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

1 Files Affected:

  • (modified) compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp (+28-14)
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index 5debf13ab9815c..4dbaff9cef4aac 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -368,17 +368,32 @@ INTERCEPTOR(void, OSSpinLockLock, volatile OSSpinLock *lock) {
   return REAL(OSSpinLockLock)(lock);
 }
 #pragma clang diagnostic pop
+#define RTSAN_MAYBE_INTERCEPT_OSSPINLOCKLOCK INTERCEPT_FUNCTION(OSSpinLockLock)
+#else
+#define RTSAN_MAYBE_INTERCEPT_OSSPINLOCKLOCK
+#endif // SANITIZER_APPLE
 
+#if SANITIZER_APPLE
 INTERCEPTOR(void, os_unfair_lock_lock, os_unfair_lock_t lock) {
   __rtsan_notify_intercepted_call("os_unfair_lock_lock");
   return REAL(os_unfair_lock_lock)(lock);
 }
-#elif SANITIZER_LINUX
+#define RTSAN_MAYBE_INTERCEPT_OS_UNFAIR_LOCK_LOCK                              \
+  INTERCEPT_FUNCTION(os_unfair_lock_lock)
+#else
+#define RTSAN_MAYBE_INTERCEPT_OS_UNFAIR_LOCK_LOCK
+#endif // SANITIZER_APPLE
+
+#if SANITIZER_LINUX
 INTERCEPTOR(int, pthread_spin_lock, pthread_spinlock_t *spinlock) {
   __rtsan_notify_intercepted_call("pthread_spin_lock");
   return REAL(pthread_spin_lock)(spinlock);
 }
-#endif
+#define RTSAN_MAYBE_INTERCEPT_PTHREAD_SPIN_LOCK                                \
+  INTERCEPT_FUNCTION(pthread_spin_lock)
+#else
+#define RTSAN_MAYBE_INTERCEPT_PTHREAD_SPIN_LOCK
+#endif // SANITIZER_LINUX
 
 INTERCEPTOR(int, pthread_create, pthread_t *thread, const pthread_attr_t *attr,
             void *(*start_routine)(void *), void *arg) {
@@ -539,6 +554,9 @@ INTERCEPTOR(void *, memalign, size_t alignment, size_t size) {
   __rtsan_notify_intercepted_call("memalign");
   return REAL(memalign)(alignment, size);
 }
+#define RTSAN_MAYBE_INTERCEPT_MEMALIGN INTERCEPT_FUNCTION(memalign)
+#else
+#define RTSAN_MAYBE_INTERCEPT_MEMALIGN
 #endif
 
 #if SANITIZER_INTERCEPT_PVALLOC
@@ -546,6 +564,9 @@ INTERCEPTOR(void *, pvalloc, size_t size) {
   __rtsan_notify_intercepted_call("pvalloc");
   return REAL(pvalloc)(size);
 }
+#define RTSAN_MAYBE_INTERCEPT_PVALLOC INTERCEPT_FUNCTION(pvalloc)
+#else
+#define RTSAN_MAYBE_INTERCEPT_PVALLOC
 #endif
 
 INTERCEPTOR(void *, mmap, void *addr, size_t length, int prot, int flags,
@@ -783,12 +804,8 @@ void __rtsan::InitializeInterceptors() {
   INTERCEPT_FUNCTION(munmap);
   INTERCEPT_FUNCTION(shm_open);
   INTERCEPT_FUNCTION(shm_unlink);
-#if SANITIZER_INTERCEPT_MEMALIGN
-  INTERCEPT_FUNCTION(memalign);
-#endif
-#if SANITIZER_INTERCEPT_PVALLOC
-  INTERCEPT_FUNCTION(pvalloc);
-#endif
+  RTSAN_MAYBE_INTERCEPT_MEMALIGN;
+  RTSAN_MAYBE_INTERCEPT_PVALLOC;
 
   INTERCEPT_FUNCTION(open);
   RTSAN_MAYBE_INTERCEPT_OPEN64;
@@ -820,12 +837,9 @@ void __rtsan::InitializeInterceptors() {
   INTERCEPT_FUNCTION(dup2);
   INTERCEPT_FUNCTION(ioctl);
 
-#if SANITIZER_APPLE
-  INTERCEPT_FUNCTION(OSSpinLockLock);
-  INTERCEPT_FUNCTION(os_unfair_lock_lock);
-#elif SANITIZER_LINUX
-  INTERCEPT_FUNCTION(pthread_spin_lock);
-#endif
+  RTSAN_MAYBE_INTERCEPT_OSSPINLOCKLOCK;
+  RTSAN_MAYBE_INTERCEPT_OS_UNFAIR_LOCK_LOCK;
+  RTSAN_MAYBE_INTERCEPT_PTHREAD_SPIN_LOCK;
 
   INTERCEPT_FUNCTION(pthread_create);
   INTERCEPT_FUNCTION(pthread_mutex_lock);

@cjappl cjappl merged commit f28e071 into llvm:main Nov 29, 2024
10 checks passed
@cjappl cjappl deleted the cleanup_MAYBE_style branch November 29, 2024 23:50
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.

2 participants