From a691030f68dc315ab618d857a57cfffde1371a5c Mon Sep 17 00:00:00 2001 From: jakub Date: Thu, 19 Mar 2015 10:12:34 +0000 Subject: [PATCH] PR sanitizer/65400 * tsan.c (instrument_gimple): Clear tail call flag on calls. * c-c++-common/tsan/pr65400-3.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@221512 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 7 +++ gcc/testsuite/ChangeLog | 5 ++ gcc/testsuite/c-c++-common/tsan/pr65400-3.c | 75 +++++++++++++++++++++++++++++ gcc/tsan.c | 4 ++ 4 files changed, 91 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/tsan/pr65400-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 251fc3a8ec7..467b445458b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2015-03-19 Bernd Edlinger + Jakub Jelinek + + PR sanitizer/65400 + * tsan.c (instrument_gimple): Clear tail call flag on + calls. + 2015-03-19 Jakub Jelinek PR sanitizer/65400 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 378fba23cf2..92ad9e1c98c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-03-19 Jakub Jelinek + + PR sanitizer/65400 + * c-c++-common/tsan/pr65400-3.c: New test. + 2015-03-19 Paolo Carlini PR c++/59686 diff --git a/gcc/testsuite/c-c++-common/tsan/pr65400-3.c b/gcc/testsuite/c-c++-common/tsan/pr65400-3.c new file mode 100644 index 00000000000..9483bb6c746 --- /dev/null +++ b/gcc/testsuite/c-c++-common/tsan/pr65400-3.c @@ -0,0 +1,75 @@ +/* PR sanitizer/65400 */ +/* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-fno-omit-frame-pointer -ldl" } */ + +#include +#include "tsan_barrier.h" + +static pthread_barrier_t barrier; +int v; + +int +fn1 (int a, int b, int c) +{ + int r = (a ^ b) % c; + r = r * a * b + c; + r = (r ^ b) % c; + return r; +} + +int +fn2 (int a, int b, int c) +{ + int r = (a ^ b) % c; + r = r * a * b + c; + r = (r ^ b) % c; + return r; +} + +__attribute__((noinline, noclone)) void +foo (void) +{ + barrier_wait (&barrier); + barrier_wait (&barrier); + v++; +} + +__attribute__((noinline, noclone)) void +bar (void) +{ + int (*fna) (int, int, int); + int (*fnb) (int, int, int); + int i; + asm ("" : "=g" (fna) : "0" (fn1)); + asm ("" : "=g" (fnb) : "0" (fn2)); + for (i = 0; i < 128; i++) + { + fna (0, 0, i + 1); + fnb (0, 0, i + 1); + } + foo (); +} + +__attribute__((noinline, noclone)) void * +tf (void *arg) +{ + (void) arg; + bar (); + return NULL; +} + +int +main () +{ + pthread_t th; + barrier_init (&barrier, 2); + if (pthread_create (&th, NULL, tf, NULL)) + return 0; + barrier_wait (&barrier); + v++; + barrier_wait (&barrier); + pthread_join (th, NULL); + return 0; +} + +/* { dg-output "WARNING: ThreadSanitizer: data race.*#2 _?tf" } */ diff --git a/gcc/tsan.c b/gcc/tsan.c index ae89d5fdaf6..ebafbb03cbd 100644 --- a/gcc/tsan.c +++ b/gcc/tsan.c @@ -680,6 +680,10 @@ instrument_gimple (gimple_stmt_iterator *gsi) && (gimple_call_fndecl (stmt) != builtin_decl_implicit (BUILT_IN_TSAN_INIT))) { + /* All functions with function call will have exit instrumented, + therefore no function calls other than __tsan_func_exit + shall appear in the functions. */ + gimple_call_set_tail (as_a (stmt), false); if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) instrument_builtin_call (gsi); return true; -- 2.11.4.GIT