llvm-project
65 строк · 2.0 Кб
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//===----------------------------------------------------------------------===//
8
9// Forced unwinding causes std::terminate when going through noexcept.
10
11// UNSUPPORTED: no-exceptions, c++03
12
13// VE only supports SjLj and doesn't provide _Unwind_ForcedUnwind.
14// UNSUPPORTED: target={{ve-.*}}
15
16// These tests fail on previously released dylibs, investigation needed.
17// XFAIL: stdlib=system && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14|15}}
18// XFAIL: stdlib=system && target={{.+}}-apple-macosx{{11.0|12.0}}
19
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>27
28template <typename T>29struct Stop;30
31template <typename R, typename... Args>32struct Stop<R (*)(Args...)> {33// The third argument of _Unwind_Stop_Fn is uint64_t in Itanium C++ ABI/LLVM34// libunwind while _Unwind_Exception_Class in libgcc.35typedef typename std::tuple_element<2, std::tuple<Args...>>::type type;36
37static _Unwind_Reason_Code stop(int, _Unwind_Action actions, type,38struct _Unwind_Exception*,39struct _Unwind_Context*, void*) {40if (actions & _UA_END_OF_STACK)41abort();42return _URC_NO_REASON;43}44};45
46static void forced_unwind() {47_Unwind_Exception* exc = new _Unwind_Exception;48memset(&exc->exception_class, 0, sizeof(exc->exception_class));49exc->exception_cleanup = 0;50_Unwind_ForcedUnwind(exc, Stop<_Unwind_Stop_Fn>::stop, 0);51abort();52}
53
54static void test() noexcept { forced_unwind(); }55
56static void terminate() { exit(0); }57
58int main(int, char**) {59std::set_terminate(terminate);60try {61test();62} catch (...) {63}64abort();65}
66