Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / builtins / Unit / gcc_personality_test_helper.cxx
blobe44b814424a1a1da2efdcea557ad3ebba37ce354
1 #include <stdlib.h>
2 #include <stdio.h>
4 extern "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();
14 static int* foo_x = NULL;
15 void register_foo_local(int* x)
17 foo_x = x;
20 static int* bar_x = NULL;
21 void register_bar_local(int* x)
23 bar_x = x;
26 static bool foo_clean_called = false;
27 void foo_clean(void* x)
29 if ( foo_x == NULL )
30 abort();
31 if ( foo_x != (int*)x)
32 abort();
33 foo_clean_called = true;
36 static bool bar_clean_called = false;
37 void bar_clean(void* x)
39 if ( bar_x == NULL )
40 abort();
41 if ( bar_x != (int*)x)
42 abort();
43 bar_clean_called = true;
46 void done_foo()
50 void done_bar()
52 throw "done";
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.
63 int main()
65 try {
66 foo();
68 catch(...) {
69 if ( !foo_clean_called )
70 abort();
71 if ( !bar_clean_called )
72 abort();
73 return 0;
75 abort();