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 #include <exception> 14 #include <stdlib.h> 15 #include <stdio.h> 16 #include <string.h> 17 #include <unwind.h> 18 #include <tuple> 19 #include <__cxxabi_config.h> 20 21 #if defined(_LIBCXXABI_ARM_EHABI) 22 int main(int, char**) { 23 return 0; 24 } 25 #else 26 template <typename T> 27 struct Stop; 28 29 template <typename R, typename... Args> 30 struct Stop<R (*)(Args...)> { 31 // The third argument of _Unwind_Stop_Fn is uint64_t in Itanium C++ ABI/LLVM 32 // libunwind while _Unwind_Exception_Class in libgcc. 33 typedef typename std::tuple_element<2, std::tuple<Args...>>::type type; 34 35 static _Unwind_Reason_Code stop(int, _Unwind_Action actions, type, 36 struct _Unwind_Exception*, 37 struct _Unwind_Context*, void*) { 38 if (actions & _UA_END_OF_STACK) 39 abort(); 40 return _URC_NO_REASON; 41 } 42 }; 43 44 static void forced_unwind() { 45 _Unwind_Exception* exc = new _Unwind_Exception; 46 exc->exception_class = 0; 47 exc->exception_cleanup = 0; 48 _Unwind_ForcedUnwind(exc, Stop<_Unwind_Stop_Fn>::stop, 0); 49 abort(); 50 } 51 52 static void test() noexcept { forced_unwind(); } 53 54 static void terminate() { exit(0); } 55 56 int main(int, char**) { 57 std::set_terminate(terminate); 58 try { 59 test(); 60 } catch (...) { 61 } 62 abort(); 63 } 64 #endif 65