Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxxabi / test / forced_unwind2.pass.cpp
blob65f5d5dd2e05cc9ec9f2f2697dddf742e7809684
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 // 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}}
20 #include <exception>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <unwind.h>
25 #include <tuple>
26 #include <__cxxabi_config.h>
28 template <typename T>
29 struct Stop;
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)
41 abort();
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);
51 abort();
54 static void test() noexcept { forced_unwind(); }
56 static void terminate() { exit(0); }
58 int main(int, char**) {
59 std::set_terminate(terminate);
60 try {
61 test();
62 } catch (...) {
64 abort();