OSDN Git Service

* c-decl.c (declspecs_add_type): Don't pedwarn for _Complex in
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / cleanup-5.c
1 /* { dg-do run } */
2 /* { dg-options "-fexceptions" } */
3 /* Verify that cleanups work with exception handling.  */
4
5 #include <unwind.h>
6 #include <stdlib.h>
7
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)
14 {
15   if (actions & _UA_END_OF_STACK)
16     abort ();
17   return _URC_NO_REASON;
18 }
19
20 static 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
35 static void handler (void *p __attribute__((unused)))
36 {
37   exit (0);
38 }
39
40 static void doit ()
41 {
42   char dummy __attribute__((cleanup (handler)));
43   force_unwind ();
44 }
45
46 int main()
47
48   doit ();
49   abort ();
50 }