[X86] avx512-pmovxrm.ll - replace X32 checks with X86. NFC.
[llvm-project.git] / libcxxabi / test / forced_unwind3.pass.cpp
blobe852ab592292f44c2a18f0e4effb20a3314d8dad
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 // Let's run ForcedUnwind until it reaches end of the stack, this test simulates
10 // what pthread_cancel does.
12 // UNSUPPORTED: c++03
13 // UNSUPPORTED: no-threads
14 // UNSUPPORTED: no-exceptions
16 // VE only supports SjLj and doesn't provide _Unwind_ForcedUnwind.
17 // UNSUPPORTED: target={{ve-.*}}
19 #include <assert.h>
20 #include <exception>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unwind.h>
24 #include <thread>
25 #include <tuple>
26 #include <__cxxabi_config.h>
28 // TODO: dump version back to 14 once clang is updated on the CI.
29 #if defined(_LIBCXXABI_ARM_EHABI) && defined(__clang__) && __clang_major__ < 15
30 // _Unwind_ForcedUnwind is not available or broken before version 14.
31 int main(int, char**) { return 0; }
33 #else
34 static bool destructorCalled = false;
36 struct myClass {
37 myClass() {}
38 ~myClass() {
39 assert(destructorCalled == false);
40 destructorCalled = true;
44 template <typename T>
45 struct Stop;
47 template <typename R, typename... Args>
48 struct Stop<R (*)(Args...)> {
49 // The third argument of _Unwind_Stop_Fn is uint64_t in Itanium C++ ABI/LLVM
50 // libunwind while _Unwind_Exception_Class in libgcc.
51 typedef typename std::tuple_element<2, std::tuple<Args...>>::type type;
53 static _Unwind_Reason_Code stop(int, _Unwind_Action actions, type, _Unwind_Exception*, struct _Unwind_Context*,
54 void*) {
55 if (actions & _UA_END_OF_STACK) {
56 assert(destructorCalled == true);
57 exit(0);
59 return _URC_NO_REASON;
63 static void forced_unwind() {
64 _Unwind_Exception* exc = new _Unwind_Exception;
65 memset(&exc->exception_class, 0, sizeof(exc->exception_class));
66 exc->exception_cleanup = 0;
67 _Unwind_ForcedUnwind(exc, Stop<_Unwind_Stop_Fn>::stop, 0);
68 abort();
71 __attribute__((__noinline__)) static void test() {
72 myClass c{};
73 forced_unwind();
74 abort();
77 int main(int, char**) {
78 std::thread t{test};
79 t.join();
80 return -1;
82 #endif