OSDN Git Service

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