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 // Forced unwinding causes std::terminate when going through noexcept.
11 // UNSUPPORTED: no-exceptions, c++03
13 // VE only supports SjLj and doesn't provide _Unwind_ForcedUnwind.
14 // UNSUPPORTED: target={{ve-.*}}
16 // These tests fail on previously released dylibs, investigation needed.
17 // XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14|15}}
18 // XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx{{11.0|12.0}}
26 #include <__cxxabi_config.h>
31 template <typename R
, typename
... Args
>
32 struct Stop
<R (*)(Args
...)> {
33 // The third argument of _Unwind_Stop_Fn is uint64_t in Itanium C++ ABI/LLVM
34 // libunwind while _Unwind_Exception_Class in libgcc.
35 typedef typename
std::tuple_element
<2, std::tuple
<Args
...>>::type type
;
37 static _Unwind_Reason_Code
stop(int, _Unwind_Action actions
, type
,
38 struct _Unwind_Exception
*,
39 struct _Unwind_Context
*, void*) {
40 if (actions
& _UA_END_OF_STACK
)
42 return _URC_NO_REASON
;
46 static void forced_unwind() {
47 _Unwind_Exception
* exc
= new _Unwind_Exception
;
48 memset(&exc
->exception_class
, 0, sizeof(exc
->exception_class
));
49 exc
->exception_cleanup
= 0;
50 _Unwind_ForcedUnwind(exc
, Stop
<_Unwind_Stop_Fn
>::stop
, 0);
54 static void test() noexcept
{ forced_unwind(); }
56 static void terminate() { exit(0); }
58 int main(int, char**) {
59 std::set_terminate(terminate
);