blob: eb64d82e612cda990ced8b2b3f4ae2a6308f9b20 [file] [log] [blame]
Daniel Dunbarfd089992009-06-26 16:47:03 +00001//===-- gcc_personality_test_helper.cxx -----------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include <stdlib.h>
11#include <stdio.h>
12
13extern "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
23static int* foo_x = NULL;
24void register_foo_local(int* x)
25{
26 foo_x = x;
27}
28
29static int* bar_x = NULL;
30void register_bar_local(int* x)
31{
32 bar_x = x;
33}
34
35static bool foo_clean_called = false;
36void 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
45static bool bar_clean_called = false;
46void 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
55void done_foo()
56{
57}
58
59void 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//
72int 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}