[llvm-commits] [compiler-rt] r172714 - in /compiler-rt/trunk/lib/tsan: lit_tests/race_on_read.cc rtl/tsan_interceptors.cc
Kostya Serebryany
kcc at google.com
Thu Jan 17 05:18:40 PST 2013
Author: kcc
Date: Thu Jan 17 07:18:40 2013
New Revision: 172714
URL: http://llvm.org/viewvc/llvm-project?rev=172714&view=rev
Log:
[tsan] add write_range/read_range hooks to common interceptors called from tsan (to find races on read/pread/etc)
Added:
compiler-rt/trunk/lib/tsan/lit_tests/race_on_read.cc
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
Added: compiler-rt/trunk/lib/tsan/lit_tests/race_on_read.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/race_on_read.cc?rev=172714&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/race_on_read.cc (added)
+++ compiler-rt/trunk/lib/tsan/lit_tests/race_on_read.cc Thu Jan 17 07:18:40 2013
@@ -0,0 +1,32 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+int fd;
+char buf;
+
+void *Thread(void *x) {
+ read(fd, &buf, 1);
+ return NULL;
+}
+
+int main() {
+ fd = open("/dev/random", O_RDONLY);
+ if (fd < 0) return 1;
+ pthread_t t[2];
+ pthread_create(&t[0], NULL, Thread, NULL);
+ pthread_create(&t[1], NULL, Thread, NULL);
+ pthread_join(t[0], NULL);
+ pthread_join(t[1], NULL);
+ close(fd);
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Write of size 1
+// CHECK: #0 read
+// CHECK: Previous write of size 1
+// CHECK: #0 read
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=172714&r1=172713&r2=172714&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu Jan 17 07:18:40 2013
@@ -1618,8 +1618,10 @@
return pid;
}
-#define COMMON_INTERCEPTOR_WRITE_RANGE(ptr, size) // FIXME
-#define COMMON_INTERCEPTOR_READ_RANGE(ptr, size) // FIXME
+#define COMMON_INTERCEPTOR_WRITE_RANGE(ptr, size) \
+ MemoryAccessRange(thr, pc, (uptr)ptr, size, true)
+#define COMMON_INTERCEPTOR_READ_RANGE(ptr, size) \
+ MemoryAccessRange(thr, pc, (uptr)ptr, size, false)
#define COMMON_INTERCEPTOR_ENTER(func, ...) \
SCOPED_TSAN_INTERCEPTOR(func, __VA_ARGS__)
#define COMMON_INTERCEPTOR_FD_ACQUIRE(fd) FdAcquire(thr, pc, fd)
More information about the llvm-commits
mailing list