1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Let's run ForcedUnwind until it reaches end of the stack, this test simulates
10 // what pthread_cancel does.
13 // UNSUPPORTED: no-threads
14 // UNSUPPORTED: no-exceptions
16 // VE only supports SjLj and doesn't provide _Unwind_ForcedUnwind.
17 // UNSUPPORTED: target={{ve-.*}}
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; }
34 static bool destructorCalled
= false;
39 assert(destructorCalled
== false);
40 destructorCalled
= true;
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
*,
55 if (actions
& _UA_END_OF_STACK
) {
56 assert(destructorCalled
== true);
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);
71 __attribute__((__noinline__
)) static void test() {
77 int main(int, char**) {