[compiler-rt] r248522 - tsan: add test for issue #602

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 10:38:56 PDT 2015


Author: dvyukov
Date: Thu Sep 24 12:38:56 2015
New Revision: 248522

URL: http://llvm.org/viewvc/llvm-project?rev=248522&view=rev
Log:
tsan: add test for issue #602


Added:
    compiler-rt/trunk/test/tsan/atomic_free3.cc

Added: compiler-rt/trunk/test/tsan/atomic_free3.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/atomic_free3.cc?rev=248522&view=auto
==============================================================================
--- compiler-rt/trunk/test/tsan/atomic_free3.cc (added)
+++ compiler-rt/trunk/test/tsan/atomic_free3.cc Thu Sep 24 12:38:56 2015
@@ -0,0 +1,28 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include "test.h"
+
+// Test for https://github.com/google/sanitizers/issues/602
+
+void *Thread(void *a) {
+  __atomic_store_n((int*)a, 1, __ATOMIC_RELAXED);
+  return 0;
+}
+
+int main() {
+  int *a = new int(0);
+  pthread_t t;
+  pthread_create(&t, 0, Thread, a);
+  while (__atomic_load_n(a, __ATOMIC_RELAXED) == 0)
+    pthread_yield();
+  delete a;
+  pthread_join(t, 0);
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK:   Write
+// CHECK:     #0 operator delete
+// CHECK:     #1 main
+
+// CHECK:   Previous atomic write
+// CHECK:     #0 __tsan_atomic32_store
+// CHECK:     #1 Thread




More information about the llvm-commits mailing list