Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / on_exit.cpp
blob2dadd68c144a41b7716203c421b6b64ad2e8c9f6
1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
3 // on_exit() is not available on Darwin.
4 // UNSUPPORTED: darwin
6 #include "test.h"
8 volatile long global;
10 void *thread(void *x) {
11 global++;
12 barrier_wait(&barrier);
13 return nullptr;
16 void on_exit_callback(int status, void *arg) {
17 fprintf(stderr, "on_exit_callback(%d, %lu)\n", status, (long)arg);
18 global++;
21 int main() {
22 on_exit(on_exit_callback, (void *)42l);
23 barrier_init(&barrier, 2);
24 pthread_t th;
25 pthread_create(&th, nullptr, thread, nullptr);
26 pthread_detach(th);
27 barrier_wait(&barrier);
28 return 2;
31 // CHECK: on_exit_callback(2, 42)
32 // CHECK: WARNING: ThreadSanitizer: data race
33 // CHECK: Write of size 8
34 // CHECK: #0 on_exit_callback
35 // CHECK: #1 on_exit_callback_installed_at
36 // CHECK: #2 main