2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / gcc.dg / cleanup-5.c
blobf5306db47526af3822f13f03b49097edc3a02c74
1 /* { dg-do run } */
2 /* { dg-options "-fexceptions" } */
3 /* Verify that cleanups work with exception handling. */
5 #include <unwind.h>
6 #include <stdlib.h>
8 static _Unwind_Reason_Code
9 force_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)
15 if (actions & _UA_END_OF_STACK)
16 abort ();
17 return _URC_NO_REASON;
20 static void force_unwind ()
22 struct _Unwind_Exception *exc = malloc (sizeof (*exc));
23 exc->exception_class = 0;
24 exc->exception_cleanup = 0;
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
32 abort ();
35 static void handler (void *p __attribute__((unused)))
37 exit (0);
40 static void doit ()
42 char dummy __attribute__((cleanup (handler)));
43 force_unwind ();
46 int main()
48 doit ();
49 abort ();