1#include <stdlib.h>
2#include <stdio.h>
3
4extern "C" {
5 extern void foo_clean(void* x);
6 extern void bar_clean(void* x);
7 extern void register_foo_local(int* x);
8 extern void register_bar_local(int* x);
9 extern void done_foo();
10 extern void done_bar();
11 extern void foo();
12}
13
14static int* foo_x = NULL;
15void register_foo_local(int* x)
16{
17 foo_x = x;
18}
19
20static int* bar_x = NULL;
21void register_bar_local(int* x)
22{
23 bar_x = x;
24}
25
26static bool foo_clean_called = false;
27void foo_clean(void* x)
28{
29 if ( foo_x == NULL )
30 abort();
31 if ( foo_x != (int*)x)
32 abort();
33 foo_clean_called = true;
34}
35
36static bool bar_clean_called = false;
37void bar_clean(void* x)
38{
39 if ( bar_x == NULL )
40 abort();
41 if ( bar_x != (int*)x)
42 abort();
43 bar_clean_called = true;
44}
45
46void done_foo()
47{
48}
49
50void done_bar()
51{
52 throw "done";
53}
54
55
56//
57// foo() is in gcc_personality_test.c and calls bar() which
58// calls done_bar() which throws an exception.
59// main() will catch the exception and verify that the cleanup
60// routines for foo() and bar() were called by the personality
61// function.
62//
63int main()
64{
65 try {
66 foo();
67 }
68 catch(...) {
69 if ( !foo_clean_called )
70 abort();
71 if ( !bar_clean_called )
72 abort();
73 return 0;
74 }
75 abort();
76}
77

source code of compiler-rt/test/builtins/Unit/gcc_personality_test_helper.cxx