From 9ea3bd5a1ccec785563faf82e08f6d9d6cb1ec0b Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 25 Nov 2021 18:55:42 +0100 Subject: [PATCH] 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 --- compiler-rt/test/tsan/atexit5.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 compiler-rt/test/tsan/atexit5.cpp diff --git a/compiler-rt/test/tsan/atexit5.cpp b/compiler-rt/test/tsan/atexit5.cpp new file mode 100644 index 0000000..90649cc --- /dev/null +++ b/compiler-rt/test/tsan/atexit5.cpp @@ -0,0 +1,26 @@ +// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s +#include "test.h" +#include + +std::unique_ptr 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 -- 2.7.4