[compiler-rt] 8214764 - tsan: declare annotations in test.h
Dmitry Vyukov via llvm-commits
llvm-commits at lists.llvm.org
Tue May 11 22:22:44 PDT 2021
Author: Dmitry Vyukov
Date: 2021-05-12T07:22:39+02:00
New Revision: 8214764f35e1b764fb939e18f16e11aa43073469
URL: https://github.com/llvm/llvm-project/commit/8214764f35e1b764fb939e18f16e11aa43073469
DIFF: https://github.com/llvm/llvm-project/commit/8214764f35e1b764fb939e18f16e11aa43073469.diff
LOG: tsan: declare annotations in test.h
We already declare subset of annotations in test.h.
But some are duplicated and declared in tests.
Move all annotation declarations to test.h.
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D102152
Added:
Modified:
compiler-rt/test/tsan/annotate_happens_before.cpp
compiler-rt/test/tsan/benign_race.cpp
compiler-rt/test/tsan/ignore_sync.cpp
compiler-rt/test/tsan/mutex_bad_read_lock.cpp
compiler-rt/test/tsan/mutex_bad_read_unlock.cpp
compiler-rt/test/tsan/mutex_bad_unlock.cpp
compiler-rt/test/tsan/mutex_double_lock.cpp
compiler-rt/test/tsan/mutexset5.cpp
compiler-rt/test/tsan/signal_sync2.cpp
compiler-rt/test/tsan/test.h
compiler-rt/test/tsan/thread_end_with_ignore.cpp
compiler-rt/test/tsan/thread_end_with_ignore2.cpp
compiler-rt/test/tsan/thread_end_with_ignore3.cpp
compiler-rt/test/tsan/thread_name.cpp
Removed:
################################################################################
diff --git a/compiler-rt/test/tsan/annotate_happens_before.cpp b/compiler-rt/test/tsan/annotate_happens_before.cpp
index 011661699a7a..86a8669681e1 100644
--- a/compiler-rt/test/tsan/annotate_happens_before.cpp
+++ b/compiler-rt/test/tsan/annotate_happens_before.cpp
@@ -7,24 +7,8 @@ Annotations usage example.
Tsan does not see synchronization in barrier_wait.
ANNOTATE_HAPPENS_BEFORE/AFTER communicate the synchronization to tsan
and prevent the race report.
-
-If the compiler does not support __has_feature macro, then you can build with
-CFLAGS="-fsanitize=thread -DTHREAD_SANITIZER" and then use
-#ifdef THREAD_SANITIZER to enabled annotations.
*/
-#if defined(__has_feature) && __has_feature(thread_sanitizer)
-# define ANNOTATE_HAPPENS_BEFORE(addr) \
- AnnotateHappensBefore(__FILE__, __LINE__, (void*)(addr))
-# define ANNOTATE_HAPPENS_AFTER(addr) \
- AnnotateHappensAfter(__FILE__, __LINE__, (void*)(addr))
-extern "C" void AnnotateHappensBefore(const char *f, int l, void *addr);
-extern "C" void AnnotateHappensAfter(const char *f, int l, void *addr);
-#else
-# define ANNOTATE_HAPPENS_BEFORE(addr)
-# define ANNOTATE_HAPPENS_AFTER(addr)
-#endif
-
int Global;
void *Thread1(void *x) {
diff --git a/compiler-rt/test/tsan/benign_race.cpp b/compiler-rt/test/tsan/benign_race.cpp
index 90722aa93157..53e820d9507f 100644
--- a/compiler-rt/test/tsan/benign_race.cpp
+++ b/compiler-rt/test/tsan/benign_race.cpp
@@ -4,15 +4,6 @@
int Global;
int WTFGlobal;
-extern "C" {
-void AnnotateBenignRaceSized(const char *f, int l,
- void *mem, unsigned int size, const char *desc);
-void WTFAnnotateBenignRaceSized(const char *f, int l,
- void *mem, unsigned int size,
- const char *desc);
-}
-
-
void *Thread(void *x) {
Global = 42;
WTFGlobal = 142;
@@ -22,11 +13,8 @@ void *Thread(void *x) {
int main() {
barrier_init(&barrier, 2);
- AnnotateBenignRaceSized(__FILE__, __LINE__,
- &Global, sizeof(Global), "Race on Global");
- WTFAnnotateBenignRaceSized(__FILE__, __LINE__,
- &WTFGlobal, sizeof(WTFGlobal),
- "Race on WTFGlobal");
+ ANNOTATE_BENIGN_RACE(Global);
+ WTF_ANNOTATE_BENIGN_RACE(WTFGlobal);
pthread_t t;
pthread_create(&t, 0, Thread, 0);
barrier_wait(&barrier);
diff --git a/compiler-rt/test/tsan/ignore_sync.cpp b/compiler-rt/test/tsan/ignore_sync.cpp
index ae24a8c49e75..7a129fb57d60 100644
--- a/compiler-rt/test/tsan/ignore_sync.cpp
+++ b/compiler-rt/test/tsan/ignore_sync.cpp
@@ -1,9 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-#include <pthread.h>
-#include <stdio.h>
-
-extern "C" void AnnotateIgnoreSyncBegin(const char*, int);
-extern "C" void AnnotateIgnoreSyncEnd(const char*, int);
+#include "test.h"
int Global;
pthread_mutex_t Mutex = PTHREAD_MUTEX_INITIALIZER;
diff --git a/compiler-rt/test/tsan/mutex_bad_read_lock.cpp b/compiler-rt/test/tsan/mutex_bad_read_lock.cpp
index 84a2976d53e4..8f1fe773900a 100644
--- a/compiler-rt/test/tsan/mutex_bad_read_lock.cpp
+++ b/compiler-rt/test/tsan/mutex_bad_read_lock.cpp
@@ -1,5 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-extern "C" void AnnotateRWLockAcquired(const char *f, int l, void *m, long rw);
+#include "test.h"
int main() {
int m = 0;
diff --git a/compiler-rt/test/tsan/mutex_bad_read_unlock.cpp b/compiler-rt/test/tsan/mutex_bad_read_unlock.cpp
index dcee51599d55..6a882618a48f 100644
--- a/compiler-rt/test/tsan/mutex_bad_read_unlock.cpp
+++ b/compiler-rt/test/tsan/mutex_bad_read_unlock.cpp
@@ -1,6 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-extern "C" void AnnotateRWLockAcquired(const char *f, int l, void *m, long rw);
-extern "C" void AnnotateRWLockReleased(const char *f, int l, void *m, long rw);
+#include "test.h"
int main() {
int m = 0;
diff --git a/compiler-rt/test/tsan/mutex_bad_unlock.cpp b/compiler-rt/test/tsan/mutex_bad_unlock.cpp
index 6b483cf17eda..a31485ab6009 100644
--- a/compiler-rt/test/tsan/mutex_bad_unlock.cpp
+++ b/compiler-rt/test/tsan/mutex_bad_unlock.cpp
@@ -1,5 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-extern "C" void AnnotateRWLockReleased(const char *f, int l, void *m, long rw);
+#include "test.h"
int main() {
int m = 0;
diff --git a/compiler-rt/test/tsan/mutex_double_lock.cpp b/compiler-rt/test/tsan/mutex_double_lock.cpp
index cd1e87df481b..2bef93ace677 100644
--- a/compiler-rt/test/tsan/mutex_double_lock.cpp
+++ b/compiler-rt/test/tsan/mutex_double_lock.cpp
@@ -1,8 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-#include <pthread.h>
-#include <unistd.h>
-
-extern "C" void AnnotateRWLockAcquired(const char *f, int l, void *m, long rw);
+#include "test.h"
void *ThreadFunc(void *m) {
AnnotateRWLockAcquired(__FILE__, __LINE__, m, 1);
diff --git a/compiler-rt/test/tsan/mutexset5.cpp b/compiler-rt/test/tsan/mutexset5.cpp
index 16da605e0c2b..ad5a76750fb6 100644
--- a/compiler-rt/test/tsan/mutexset5.cpp
+++ b/compiler-rt/test/tsan/mutexset5.cpp
@@ -33,7 +33,7 @@ int main() {
// CHECK: #1 main {{.*}}mutexset5.cpp:[[@LINE+4]]
// CHECK: Mutex [[M2]] (0x{{.*}}) created at:
// CHECK: #0 pthread_mutex_init
- // CHECK: #1 main {{.*}}mutexset5.cpp:[[@LINE+5]]
+ // CHECK: #1 main {{.*}}mutexset5.cpp:[[@LINE+2]]
pthread_mutex_init(&mtx1, 0);
pthread_mutex_init(&mtx2, 0);
pthread_t t[2];
diff --git a/compiler-rt/test/tsan/signal_sync2.cpp b/compiler-rt/test/tsan/signal_sync2.cpp
index 163f20650756..7d00296f4339 100644
--- a/compiler-rt/test/tsan/signal_sync2.cpp
+++ b/compiler-rt/test/tsan/signal_sync2.cpp
@@ -1,19 +1,13 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
// UNSUPPORTED: darwin
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include "test.h"
+#include <errno.h>
#include <signal.h>
-#include <sys/types.h>
#include <sys/time.h>
-#include <unistd.h>
-#include <errno.h>
+#include <sys/types.h>
// Test synchronization in signal handled within IgnoreSync region.
-extern "C" void AnnotateIgnoreSyncBegin(const char *f, int l);
-extern "C" void AnnotateIgnoreSyncEnd(const char *f, int l);
-
const int kSignalCount = 500;
__thread int process_signals;
diff --git a/compiler-rt/test/tsan/test.h b/compiler-rt/test/tsan/test.h
index 4c75572da8f0..16d7a12b5862 100644
--- a/compiler-rt/test/tsan/test.h
+++ b/compiler-rt/test/tsan/test.h
@@ -69,6 +69,8 @@ const int kPCInc = 1;
extern "C" {
#endif
+void AnnotateThreadName(const char *f, int l, const char *name);
+
void AnnotateRWLockCreate(const char *f, int l, void *m);
void AnnotateRWLockCreateStatic(const char *f, int l, void *m);
void AnnotateRWLockDestroy(const char *f, int l, void *m);
@@ -80,6 +82,15 @@ void AnnotateIgnoreReadsEnd(const char *f, int l);
void AnnotateIgnoreWritesBegin(const char *f, int l);
void AnnotateIgnoreWritesEnd(const char *f, int l);
+void AnnotateIgnoreSyncBegin(const char *f, int l);
+void AnnotateIgnoreSyncEnd(const char *f, int l);
+
+void AnnotateHappensBefore(const char *f, int l, void *addr);
+void AnnotateHappensAfter(const char *f, int l, void *addr);
+
+void AnnotateBenignRaceSized(const char *f, int l, void *mem, unsigned int size, const char *desc);
+void WTFAnnotateBenignRaceSized(const char *f, int l, void *mem, unsigned int size, const char *desc);
+
#ifdef __cplusplus
}
#endif
@@ -94,6 +105,14 @@ void AnnotateIgnoreWritesEnd(const char *f, int l);
AnnotateRWLockAcquired(__FILE__, __LINE__, m, is_w)
#define ANNOTATE_RWLOCK_RELEASED(m, is_w) \
AnnotateRWLockReleased(__FILE__, __LINE__, m, is_w)
+#define ANNOTATE_HAPPENS_BEFORE(addr) \
+ AnnotateHappensBefore(__FILE__, __LINE__, (void *)(addr))
+#define ANNOTATE_HAPPENS_AFTER(addr) \
+ AnnotateHappensAfter(__FILE__, __LINE__, (void *)(addr))
+#define ANNOTATE_BENIGN_RACE(var) \
+ AnnotateBenignRaceSized(__FILE__, __LINE__, &(var), sizeof(var), #var)
+#define WTF_ANNOTATE_BENIGN_RACE(var) \
+ WTFAnnotateBenignRaceSized(__FILE__, __LINE__, &(var), sizeof(var), #var)
#ifdef __APPLE__
#define ASM_SYMBOL(symbol) "_" #symbol
diff --git a/compiler-rt/test/tsan/thread_end_with_ignore.cpp b/compiler-rt/test/tsan/thread_end_with_ignore.cpp
index 79bb08d64bcb..8bcf298e20e2 100644
--- a/compiler-rt/test/tsan/thread_end_with_ignore.cpp
+++ b/compiler-rt/test/tsan/thread_end_with_ignore.cpp
@@ -1,8 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-#include <pthread.h>
-#include <stdio.h>
-
-extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l);
+#include "test.h"
void *Thread(void *x) {
AnnotateIgnoreReadsBegin("", 0);
diff --git a/compiler-rt/test/tsan/thread_end_with_ignore2.cpp b/compiler-rt/test/tsan/thread_end_with_ignore2.cpp
index 9387ea488d5a..4bdc56060ea1 100644
--- a/compiler-rt/test/tsan/thread_end_with_ignore2.cpp
+++ b/compiler-rt/test/tsan/thread_end_with_ignore2.cpp
@@ -1,5 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-extern "C" void AnnotateIgnoreWritesBegin(const char *f, int l);
+#include "test.h"
int main() {
AnnotateIgnoreWritesBegin("", 0);
diff --git a/compiler-rt/test/tsan/thread_end_with_ignore3.cpp b/compiler-rt/test/tsan/thread_end_with_ignore3.cpp
index aa93da435146..68b042be8e1a 100644
--- a/compiler-rt/test/tsan/thread_end_with_ignore3.cpp
+++ b/compiler-rt/test/tsan/thread_end_with_ignore3.cpp
@@ -1,6 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l);
-extern "C" void AnnotateIgnoreReadsEnd(const char *f, int l);
+#include "test.h"
int main() {
AnnotateIgnoreReadsBegin("", 0);
@@ -15,8 +14,7 @@ int main() {
// CHECK: ThreadSanitizer: main thread finished with ignores enabled
// CHECK: Ignore was enabled at:
// CHECK: #0 AnnotateIgnoreReadsBegin
-// CHECK: #1 main {{.*}}thread_end_with_ignore3.cpp:10
+// CHECK: #1 main {{.*}}thread_end_with_ignore3.cpp:9
// CHECK: Ignore was enabled at:
// CHECK: #0 AnnotateIgnoreReadsBegin
-// CHECK: #1 main {{.*}}thread_end_with_ignore3.cpp:11
-
+// CHECK: #1 main {{.*}}thread_end_with_ignore3.cpp:10
diff --git a/compiler-rt/test/tsan/thread_name.cpp b/compiler-rt/test/tsan/thread_name.cpp
index 1fa055579ee0..bc65421b36d0 100644
--- a/compiler-rt/test/tsan/thread_name.cpp
+++ b/compiler-rt/test/tsan/thread_name.cpp
@@ -15,8 +15,6 @@
#define USE_PTHREAD_SETNAME_NP 0
#endif
-extern "C" void AnnotateThreadName(const char *f, int l, const char *name);
-
int Global;
void *Thread1(void *x) {
More information about the llvm-commits
mailing list