tsan: add test for __cxa_atexit
Add a test for a common C++ bug when a global object is destroyed
while background threads still use it.
Depends on D114604.
Reviewed By: vitalybuka, melver
Differential Revision: https://reviews.llvm.org/D114605
GitOrigin-RevId: 9ea3bd5a1ccec785563faf82e08f6d9d6cb1ec0b
diff --git a/test/tsan/atexit5.cpp b/test/tsan/atexit5.cpp
new file mode 100644
index 0000000..90649cc
--- /dev/null
+++ b/test/tsan/atexit5.cpp
@@ -0,0 +1,26 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include "test.h"
+#include <memory>
+
+std::unique_ptr<long> global(new long(42));
+
+void *thread(void *x) {
+ *global = 43;
+ barrier_wait(&barrier);
+ return nullptr;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ pthread_t th;
+ pthread_create(&th, nullptr, thread, nullptr);
+ pthread_detach(th);
+ barrier_wait(&barrier);
+ return 0;
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Write of size 8
+// The exact spelling and number of std frames is hard to guess.
+// CHECK: unique_ptr
+// CHECK: #{{1|2}} cxa_at_exit_wrapper