[compiler-rt] 9ea3bd5 - tsan: add test for __cxa_atexit

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 25 23:00:32 PST 2021


Author: Dmitry Vyukov
Date: 2021-11-26T08:00:29+01:00
New Revision: 9ea3bd5a1ccec785563faf82e08f6d9d6cb1ec0b

URL: https://github.com/llvm/llvm-project/commit/9ea3bd5a1ccec785563faf82e08f6d9d6cb1ec0b
DIFF: https://github.com/llvm/llvm-project/commit/9ea3bd5a1ccec785563faf82e08f6d9d6cb1ec0b.diff

LOG: 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

Added: 
    compiler-rt/test/tsan/atexit5.cpp

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/tsan/atexit5.cpp b/compiler-rt/test/tsan/atexit5.cpp
new file mode 100644
index 000000000000..90649cc55d84
--- /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 <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


        


More information about the llvm-commits mailing list