Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxxabi / test / thread_local_destruction_order.pass.cpp
blobc7e7717d6f04f99e4babba5958aa81e977253cc9
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
10 // UNSUPPORTED: no-threads
12 // XFAIL: LIBCXX-FREEBSD-FIXME
14 // TODO: This test does start working with newer updates of the mingw-w64
15 // toolchain, when it includes the following commit:
16 // https://github.com/mingw-w64/mingw-w64/commit/71eddccd746c56d9cde28bb5620d027d49259de9
17 // Thus, remove this UNSUPPORTED marking after the next update of the CI
18 // toolchain.
19 // UNSUPPORTED: target={{.*-windows-gnu}}
21 #include <cassert>
22 #include <thread>
24 #include "make_test_thread.h"
26 int seq = 0;
28 class OrderChecker {
29 public:
30 explicit OrderChecker(int n) : n_{n} { }
32 ~OrderChecker() {
33 assert(seq++ == n_);
36 private:
37 int n_;
40 template <int ID>
41 class CreatesThreadLocalInDestructor {
42 public:
43 ~CreatesThreadLocalInDestructor() {
44 thread_local OrderChecker checker{ID};
48 OrderChecker global{7};
50 void thread_fn() {
51 static OrderChecker fn_static{5};
52 thread_local CreatesThreadLocalInDestructor<2> creates_tl2;
53 thread_local OrderChecker fn_thread_local{1};
54 thread_local CreatesThreadLocalInDestructor<0> creates_tl0;
57 int main(int, char**) {
58 static OrderChecker fn_static{6};
60 support::make_test_thread(thread_fn).join();
61 assert(seq == 3);
63 thread_local OrderChecker fn_thread_local{4};
64 thread_local CreatesThreadLocalInDestructor<3> creates_tl;
66 return 0;