[compiler-rt] r178534 - [TSan] Add the WTFAnnotateBenignRaceSized implementation and a test for
Alexander Potapenko
glider at google.com
Tue Apr 2 04:21:53 PDT 2013
Author: glider
Date: Tue Apr 2 06:21:53 2013
New Revision: 178534
URL: http://llvm.org/viewvc/llvm-project?rev=178534&view=rev
Log:
[TSan] Add the WTFAnnotateBenignRaceSized implementation and a test for
WTFAnnotateBenignRaceSized and AnnotateBenignRaceSized.
Added:
compiler-rt/trunk/lib/tsan/lit_tests/benign_race.cc
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_interface_ann.cc
Added: compiler-rt/trunk/lib/tsan/lit_tests/benign_race.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/benign_race.cc?rev=178534&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/benign_race.cc (added)
+++ compiler-rt/trunk/lib/tsan/lit_tests/benign_race.cc Tue Apr 2 06:21:53 2013
@@ -0,0 +1,39 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+
+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;
+ return 0;
+}
+
+int main() {
+ AnnotateBenignRaceSized(__FILE__, __LINE__,
+ &Global, sizeof(Global), "Race on Global");
+ WTFAnnotateBenignRaceSized(__FILE__, __LINE__,
+ &WTFGlobal, sizeof(WTFGlobal),
+ "Race on WTFGlobal");
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ sleep(1);
+ Global = 43;
+ WTFGlobal = 143;
+ pthread_join(t, 0);
+ printf("OK\n");
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interface_ann.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interface_ann.cc?rev=178534&r1=178533&r2=178534&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interface_ann.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interface_ann.cc Tue Apr 2 06:21:53 2013
@@ -416,6 +416,9 @@ void INTERFACE_ATTRIBUTE AnnotateThreadN
ThreadSetName(thr, name);
}
+// We deliberately omit the implementation of WTFAnnotateHappensBefore() and
+// WTFAnnotateHappensAfter(). Those are being used by Webkit to annotate
+// atomic operations, which should be handled by ThreadSanitizer correctly.
void INTERFACE_ATTRIBUTE WTFAnnotateHappensBefore(char *f, int l, uptr addr) {
SCOPED_ANNOTATION(AnnotateHappensBefore);
}
@@ -427,6 +430,7 @@ void INTERFACE_ATTRIBUTE WTFAnnotateHapp
void INTERFACE_ATTRIBUTE WTFAnnotateBenignRaceSized(
char *f, int l, uptr mem, uptr sz, char *desc) {
SCOPED_ANNOTATION(AnnotateBenignRaceSized);
+ BenignRaceImpl(f, l, mem, 1, desc);
}
int INTERFACE_ATTRIBUTE RunningOnValgrind() {
More information about the llvm-commits
mailing list