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