sanititer.def (BUILT_IN_TSAN_VPTR_UPDATE): Fixed parameters.
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Fri, 16 Jan 2015 17:49:56 +0000 (17:49 +0000)
committerBernd Edlinger <edlinger@gcc.gnu.org>
Fri, 16 Jan 2015 17:49:56 +0000 (17:49 +0000)
2015-01-16  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        * sanititer.def (BUILT_IN_TSAN_VPTR_UPDATE): Fixed parameters.
        * tsan.c (instrument_expr): Fixed parameters of __tsan_vptr_update.

gcc/testsuite/ChangeLog
2015-01-16  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        * g++.dg/tsan/vptr_benign_race.C: New testcase.
        * g++.dg/tsan/vptr_harmful_race.C: New testcase.

From-SVN: r219761

gcc/ChangeLog
gcc/sanitizer.def
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/tsan/vptr_benign_race.C [new file with mode: 0644]
gcc/testsuite/g++.dg/tsan/vptr_harmful_race.C [new file with mode: 0644]
gcc/tsan.c

index 717bdbd8d44b413151ad12ed48433aaf9e53777f..ae633bf2f10404aa5e31b4e6ce02ae1ead85608d 100644 (file)
@@ -1,3 +1,8 @@
+2015-01-16  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       * sanititer.def (BUILT_IN_TSAN_VPTR_UPDATE): Fixed parameters.
+       * tsan.c (instrument_expr): Fixed parameters of __tsan_vptr_update.
+
 2015-01-16  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        * config/arm/arm.md: Move comment about splitting Thumb1 patterns to...
index 0f18928810785de4504b2eaec5fa206edfac370d..7d149105b995ed3fd4455dd65fe2958449a4bd4d 100644 (file)
@@ -167,7 +167,7 @@ DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_FUNC_ENTRY, "__tsan_func_entry",
 DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_FUNC_EXIT, "__tsan_func_exit",
                      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
 DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_VPTR_UPDATE, "__tsan_vptr_update",
-                     BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
+                     BT_FN_VOID_PTR_PTR, ATTR_NOTHROW_LEAF_LIST)
 DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_READ1, "__tsan_read1",
                      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
 DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_READ2, "__tsan_read2",
index dc3b607886063f025388ba7d51ec0d9c6f9b44d6..cc0ab53cf63ee362247ce1119d813bde02111799 100644 (file)
@@ -1,3 +1,8 @@
+2015-01-16  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       * g++.dg/tsan/vptr_benign_race.C: New testcase.
+       * g++.dg/tsan/vptr_harmful_race.C: New testcase.
+
 2015-01-16  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/60056
diff --git a/gcc/testsuite/g++.dg/tsan/vptr_benign_race.C b/gcc/testsuite/g++.dg/tsan/vptr_benign_race.C
new file mode 100644 (file)
index 0000000..283684b
--- /dev/null
@@ -0,0 +1,49 @@
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdio.h>
+
+struct A {
+  A() {
+    sem_init(&sem_, 0, 0);
+  }
+  virtual void F() {
+  }
+  void Done() {
+    sem_post(&sem_);
+  }
+  virtual ~A() {
+  }
+  sem_t sem_;
+};
+
+struct B : A {
+  virtual void F() {
+  }
+  virtual ~B() {
+    sem_wait(&sem_);
+    sem_destroy(&sem_);
+  }
+};
+
+static A *obj = new B;
+
+void *Thread1(void *x) {
+  obj->F();
+  obj->Done();
+  return NULL;
+}
+
+void *Thread2(void *x) {
+  delete obj;
+  return NULL;
+}
+
+int main() {
+  pthread_t t[2];
+  pthread_create(&t[0], NULL, Thread1, NULL);
+  pthread_create(&t[1], NULL, Thread2, NULL);
+  pthread_join(t[0], NULL);
+  pthread_join(t[1], NULL);
+  fprintf(stderr, "PASS\n");
+}
+/* { dg-output "PASS.*" } */
diff --git a/gcc/testsuite/g++.dg/tsan/vptr_harmful_race.C b/gcc/testsuite/g++.dg/tsan/vptr_harmful_race.C
new file mode 100644 (file)
index 0000000..1473f93
--- /dev/null
@@ -0,0 +1,58 @@
+/* { dg-shouldfail "tsan" } */
+/* { dg-additional-options "-ldl" } */
+
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "tsan_barrier.h"
+
+static pthread_barrier_t barrier;
+
+struct A {
+  A() {
+    sem_init(&sem_, 0, 0);
+  }
+  virtual void F() {
+  }
+  void Done() {
+    sem_post(&sem_);
+  }
+  virtual ~A() {
+    sem_wait(&sem_);
+    sem_destroy(&sem_);
+  }
+  sem_t sem_;
+};
+
+struct B : A {
+  virtual void F() {
+  }
+  virtual ~B() { }
+};
+
+static A *obj = new B;
+
+void *Thread1(void *x) {
+  obj->F();
+  obj->Done();
+  barrier_wait(&barrier);
+  return NULL;
+}
+
+void *Thread2(void *x) {
+  barrier_wait(&barrier);
+  delete obj;
+  return NULL;
+}
+
+int main() {
+  barrier_init(&barrier, 2);
+  pthread_t t[2];
+  pthread_create(&t[0], NULL, Thread1, NULL);
+  pthread_create(&t[1], NULL, Thread2, NULL);
+  pthread_join(t[0], NULL);
+  pthread_join(t[1], NULL);
+}
+
+/* { dg-output "WARNING: ThreadSanitizer: data race on vptr.*(\n|\r\n|\r)" } */
index 7c172620367819d9ccecc063c8161bd085680f6a..ae89d5fdaf618c8f0c288e96689fce5345a1d927 100644 (file)
@@ -249,7 +249,7 @@ instrument_expr (gimple_stmt_iterator gsi, tree expr, bool is_write)
   else
     {
       builtin_decl = builtin_decl_implicit (BUILT_IN_TSAN_VPTR_UPDATE);
-      g = gimple_build_call (builtin_decl, 1, expr_ptr);
+      g = gimple_build_call (builtin_decl, 2, expr_ptr, unshare_expr (rhs));
     }
   gimple_set_location (g, loc);
   gimple_seq_add_stmt_without_update (&seq, g);