Merge reload-branch up to revision 101000
[official-gcc.git] / gcc / testsuite / gcc.dg / cleanup-9.c
blob4cf4a413fa4940aa44b842ca775f4c6c03df43e3
1 /* { dg-do run { target *-*-linux* powerpc*-*-darwin* } } */
2 /* { dg-options "-fexceptions -fnon-call-exceptions -O2" } */
3 /* Verify that cleanups work with exception handling through realtime
4 signal frames. */
6 #include <unwind.h>
7 #include <stdlib.h>
8 #include <signal.h>
10 static _Unwind_Reason_Code
11 force_unwind_stop (int version, _Unwind_Action actions,
12 _Unwind_Exception_Class exc_class,
13 struct _Unwind_Exception *exc_obj,
14 struct _Unwind_Context *context,
15 void *stop_parameter)
17 if (actions & _UA_END_OF_STACK)
18 abort ();
19 return _URC_NO_REASON;
22 static void force_unwind ()
24 struct _Unwind_Exception *exc = malloc (sizeof (*exc));
25 exc->exception_class = 0;
26 exc->exception_cleanup = 0;
28 #ifndef __USING_SJLJ_EXCEPTIONS__
29 _Unwind_ForcedUnwind (exc, force_unwind_stop, 0);
30 #else
31 _Unwind_SjLj_ForcedUnwind (exc, force_unwind_stop, 0);
32 #endif
34 abort ();
37 int count;
38 char *null;
40 static void counter (void *p __attribute__((unused)))
42 ++count;
45 static void handler (void *p __attribute__((unused)))
47 if (count != 2)
48 abort ();
49 exit (0);
52 static int __attribute__((noinline)) fn5 ()
54 char dummy __attribute__((cleanup (counter)));
55 force_unwind ();
56 return 0;
59 static void fn4 (int sig, siginfo_t *info, void *ctx)
61 char dummy __attribute__((cleanup (counter)));
62 fn5 ();
63 null = NULL;
66 static void fn3 ()
68 abort ();
71 static int __attribute__((noinline)) fn2 ()
73 *null = 0;
74 fn3 ();
75 return 0;
78 static int __attribute__((noinline)) fn1 ()
80 struct sigaction s;
81 sigemptyset (&s.sa_mask);
82 s.sa_sigaction = fn4;
83 s.sa_flags = SA_RESETHAND | SA_SIGINFO;
84 sigaction (SIGSEGV, &s, NULL);
85 sigaction (SIGBUS, &s, NULL);
86 fn2 ();
87 return 0;
90 static int __attribute__((noinline)) fn0 ()
92 char dummy __attribute__((cleanup (handler)));
93 fn1 ();
94 null = 0;
95 return 0;
98 int main()
100 fn0 ();
101 abort ();