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