From dcc6db22d8508a85ecd2b8bdcc5ae5646968c083 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 22 Sep 2021 17:56:52 +0200 Subject: [PATCH] tsan: add another deep stack test Add a test for a trace corner case that lead to a bug in experimental runtime replacement. Since it passes with the current runtime it makes sense to submit it on its own. Depends on D110264. Reviewed By: melver Differential Revision: https://reviews.llvm.org/D110265 --- compiler-rt/test/tsan/deep_stack2.cpp | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 compiler-rt/test/tsan/deep_stack2.cpp diff --git a/compiler-rt/test/tsan/deep_stack2.cpp b/compiler-rt/test/tsan/deep_stack2.cpp new file mode 100644 index 0000000..1675686 --- /dev/null +++ b/compiler-rt/test/tsan/deep_stack2.cpp @@ -0,0 +1,42 @@ +// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s +#include "test.h" + +volatile long X; +volatile long Y; +volatile int N1 = 2 << 10; +volatile int N2 = 32 << 10; +void (*volatile F)(); +void (*volatile G)(); + +static void foo() { + if (--N1) + return F(); + while (--N2) + G(); +} + +static void bar() { Y++; } + +void *Thread(void *p) { + F(); + X = 43; + barrier_wait(&barrier); + return 0; +} + +int main() { + barrier_init(&barrier, 2); + F = foo; + G = bar; + pthread_t t; + pthread_create(&t, 0, Thread, 0); + barrier_wait(&barrier); + X = 43; + pthread_join(t, 0); +} + +// CHECK: WARNING: ThreadSanitizer: data race +// CHECK: Write +// CHECK: #0 main +// CHECK: Previous write +// CHECK: #0 Thread -- 2.7.4