1 2// 3// TEST-OPTIONS: -arch i386 4// TEST-OPTIONS: -arch i386 -Wl,-no_compact_unwind 5// TEST-OPTIONS: -arch x86_64 6// TEST-OPTIONS: -arch x86_64 -Wl,-no_compact_unwind 7// TEST-OPTIONS: -arch ppc 8// 9// Tests _Unwind_ForcedUnwind() 10// 11 12#include <stdio.h> 13#include <stdlib.h> 14#include <stdint.h> 15 16#include "unwind.h" 17 18 19 20static bool exceptionCaught = false; 21 22 23static _Unwind_Reason_Code stop_func(int version, _Unwind_Action actions, uint64_t exceptionClass, 24 _Unwind_Exception* exceptionObject, _Unwind_Context* context, void* stop_parameter) 25{ 26 if ( actions & _UA_END_OF_STACK ) { 27 if ( exceptionCaught ) 28 exit(0); 29 else 30 exit(1); 31 } 32 return _URC_NO_REASON; 33} 34 35 36void test() 37{ 38 try { 39 _Unwind_Exception* except_obj = (_Unwind_Exception*)calloc(sizeof(_Unwind_Exception), 1); 40 _Unwind_ForcedUnwind(except_obj, stop_func, NULL); 41 } 42 catch(...) { 43 // forced unwindind should run this catch clause 44 exceptionCaught = true; 45 throw; 46 } 47} 48 49int main() 50{ 51 test(); 52 return 1; 53} 54 55