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
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) {
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;
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);
// 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;
// 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;
// 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;
// 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;
// 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);
// 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];
// 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;
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);
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
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
// 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);
// 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);
// 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);
// 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
#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) {