[compiler-rt] r184430 - tsan: fix potential false positive race on fd
Dmitry Vyukov
dvyukov at google.com
Thu Jun 20 07:32:12 PDT 2013
Author: dvyukov
Date: Thu Jun 20 09:32:12 2013
New Revision: 184430
URL: http://llvm.org/viewvc/llvm-project?rev=184430&view=rev
Log:
tsan: fix potential false positive race on fd
Added:
compiler-rt/trunk/lib/tsan/lit_tests/fd_close_norace2.cc
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_fd.cc
Added: compiler-rt/trunk/lib/tsan/lit_tests/fd_close_norace2.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/fd_close_norace2.cc?rev=184430&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/fd_close_norace2.cc (added)
+++ compiler-rt/trunk/lib/tsan/lit_tests/fd_close_norace2.cc Thu Jun 20 09:32:12 2013
@@ -0,0 +1,30 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int pipes[2];
+
+void *Thread(void *x) {
+ // wait for shutown signal
+ while (read(pipes[0], &x, 1) != 1) {
+ }
+ close(pipes[0]);
+ close(pipes[1]);
+ return 0;
+}
+
+int main() {
+ if (pipe(pipes))
+ return 1;
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ // send shutdown signal
+ while (write(pipes[1], &t, 1) != 1) {
+ }
+ pthread_join(t, 0);
+ printf("OK\n");
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
+// CHECK: OK
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_fd.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_fd.cc?rev=184430&r1=184429&r2=184430&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_fd.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_fd.cc Thu Jun 20 09:32:12 2013
@@ -160,9 +160,9 @@ void FdRelease(ThreadState *thr, uptr pc
FdDesc *d = fddesc(thr, pc, fd);
FdSync *s = d->sync;
DPrintf("#%d: FdRelease(%d) -> %p\n", thr->tid, fd, s);
+ MemoryRead(thr, pc, (uptr)d, kSizeLog8);
if (s)
Release(thr, pc, (uptr)s);
- MemoryRead(thr, pc, (uptr)d, kSizeLog8);
}
void FdAccess(ThreadState *thr, uptr pc, int fd) {
More information about the llvm-commits
mailing list