From cbf9a56669cf7ca630b941dce4a7e118b7012f57 Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Fri, 16 Jan 2015 17:49:56 +0000 Subject: [PATCH] sanititer.def (BUILT_IN_TSAN_VPTR_UPDATE): Fixed parameters. 2015-01-16 Bernd Edlinger * 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 * g++.dg/tsan/vptr_benign_race.C: New testcase. * g++.dg/tsan/vptr_harmful_race.C: New testcase. From-SVN: r219761 --- gcc/ChangeLog | 5 ++ gcc/sanitizer.def | 2 +- gcc/testsuite/ChangeLog | 5 ++ gcc/testsuite/g++.dg/tsan/vptr_benign_race.C | 49 ++++++++++++++++ gcc/testsuite/g++.dg/tsan/vptr_harmful_race.C | 58 +++++++++++++++++++ gcc/tsan.c | 2 +- 6 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/tsan/vptr_benign_race.C create mode 100644 gcc/testsuite/g++.dg/tsan/vptr_harmful_race.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 717bdbd8d44..ae633bf2f10 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-01-16 Bernd Edlinger + + * sanititer.def (BUILT_IN_TSAN_VPTR_UPDATE): Fixed parameters. + * tsan.c (instrument_expr): Fixed parameters of __tsan_vptr_update. + 2015-01-16 Kyrylo Tkachov * config/arm/arm.md: Move comment about splitting Thumb1 patterns to... diff --git a/gcc/sanitizer.def b/gcc/sanitizer.def index 0f189288107..7d149105b99 100644 --- a/gcc/sanitizer.def +++ b/gcc/sanitizer.def @@ -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", diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dc3b6078860..cc0ab53cf63 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-01-16 Bernd Edlinger + + * g++.dg/tsan/vptr_benign_race.C: New testcase. + * g++.dg/tsan/vptr_harmful_race.C: New testcase. + 2015-01-16 Paolo Carlini 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 index 00000000000..283684bcfa9 --- /dev/null +++ b/gcc/testsuite/g++.dg/tsan/vptr_benign_race.C @@ -0,0 +1,49 @@ +#include +#include +#include + +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 index 00000000000..1473f93ed24 --- /dev/null +++ b/gcc/testsuite/g++.dg/tsan/vptr_harmful_race.C @@ -0,0 +1,58 @@ +/* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-ldl" } */ + +#include +#include +#include +#include +#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)" } */ diff --git a/gcc/tsan.c b/gcc/tsan.c index 7c172620367..ae89d5fdaf6 100644 --- a/gcc/tsan.c +++ b/gcc/tsan.c @@ -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); -- 2.30.2