diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2013-12-24 12:55:56 +0000 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2013-12-24 12:55:56 +0000 |
| commit | ce3721057d4edf48b73de9f002b2ab5bea3d2518 (patch) | |
| tree | 8b1ec48df14209666343213f9b28bc9f4af2c5e3 /compiler-rt/lib/tsan/lit_tests/malloc_hook.cc | |
| parent | 27aea0b0b78ba51f344a3c9188ddf053b1e3b14e (diff) | |
| download | bcm5719-llvm-ce3721057d4edf48b73de9f002b2ab5bea3d2518.tar.gz bcm5719-llvm-ce3721057d4edf48b73de9f002b2ab5bea3d2518.zip | |
tsan: remove in_rtl counter
This is intended to address the following problem.
Episodically we see CHECK-failures when recursive interceptors call back into user code. Effectively we are not "in_rtl" at this point, but it's very complicated and fragile to properly maintain in_rtl property. Instead get rid of it. It was used mostly for sanity CHECKs, which basically never uncover real problems.
Instead introduce ignore_interceptors flag, which is used in very few narrow places to disable recursive interceptors (e.g. during runtime initialization).
llvm-svn: 197979
Diffstat (limited to 'compiler-rt/lib/tsan/lit_tests/malloc_hook.cc')
| -rw-r--r-- | compiler-rt/lib/tsan/lit_tests/malloc_hook.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/compiler-rt/lib/tsan/lit_tests/malloc_hook.cc b/compiler-rt/lib/tsan/lit_tests/malloc_hook.cc new file mode 100644 index 00000000000..82eb6900efd --- /dev/null +++ b/compiler-rt/lib/tsan/lit_tests/malloc_hook.cc @@ -0,0 +1,52 @@ +// RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s +#include <pthread.h> +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <stddef.h> + +static int malloc_count; +static int free_count; + +extern "C" { +void __tsan_malloc_hook(void *ptr, size_t size) { + (void)ptr; + (void)size; + __sync_fetch_and_add(&malloc_count, 1); +} + +void __tsan_free_hook(void *ptr) { + (void)ptr; + __sync_fetch_and_add(&free_count, 1); +} +} + +void *Thread1(void *x) { + ((int*)x)[0]++; + return 0; +} + +void *Thread2(void *x) { + sleep(1); + ((int*)x)[0]++; + return 0; +} + +int main() { + int *x = new int; + pthread_t t[2]; + pthread_create(&t[0], 0, Thread1, x); + pthread_create(&t[1], 0, Thread2, x); + pthread_join(t[0], 0); + pthread_join(t[1], 0); + delete x; + if (malloc_count == 0 || free_count == 0) { + fprintf(stderr, "FAILED %d %d\n", malloc_count, free_count); + exit(1); + } + fprintf(stderr, "DONE\n"); +} + +// CHECK: WARNING: ThreadSanitizer: data race +// CHECK-NOT: FAILED +// CHECK: DONE |

