tsan: add another deep stack test
authorDmitry Vyukov <dvyukov@google.com>
Wed, 22 Sep 2021 15:56:52 +0000 (17:56 +0200)
committerDmitry Vyukov <dvyukov@google.com>
Thu, 23 Sep 2021 08:45:17 +0000 (10:45 +0200)
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 [new file with mode: 0644]

diff --git a/compiler-rt/test/tsan/deep_stack2.cpp b/compiler-rt/test/tsan/deep_stack2.cpp
new file mode 100644 (file)
index 0000000..1675686
--- /dev/null
@@ -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