1/* { dg-do run { target i?86-*-linux* x86_64-*-linux* ia64-*-linux* alpha*-*-linux* powerpc*-*-linux* s390*-*-linux* sparc*-*-linux* mips*-*-linux* } } */ 2/* { dg-options "-fexceptions" } */ 3/* Verify that cleanups work with exception handling. */ 4 5#include <unwind.h> 6#include <stdlib.h> 7 8static _Unwind_Reason_Code 9force_unwind_stop (int version, _Unwind_Action actions, 10 _Unwind_Exception_Class exc_class, 11 struct _Unwind_Exception *exc_obj, 12 struct _Unwind_Context *context, 13 void *stop_parameter) 14{ 15 if (actions & _UA_END_OF_STACK) 16 abort (); 17 return _URC_NO_REASON; 18} 19 20static void force_unwind () 21{ 22 struct _Unwind_Exception *exc = malloc (sizeof (*exc)); 23 exc->exception_class = 0; 24 exc->exception_cleanup = 0; 25 26#ifndef __USING_SJLJ_EXCEPTIONS__ 27 _Unwind_ForcedUnwind (exc, force_unwind_stop, 0); 28#else 29 _Unwind_SjLj_ForcedUnwind (exc, force_unwind_stop, 0); 30#endif 31 32 abort (); 33} 34 35static void handler (void *p __attribute__((unused))) 36{ 37 exit (0); 38} 39 40static void doit () 41{ 42 char dummy __attribute__((cleanup (handler))); 43 force_unwind (); 44} 45 46int main() 47{ 48 doit (); 49 abort (); 50} 51