Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame^] | 1 | //===-- gcc_personality_test.c - Tests __gcc_personality_v0 -------------===// |
| 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 | |
| 11 | #include <stdlib.h> |
| 12 | #include <stdio.h> |
| 13 | |
| 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 | |
| 21 | |
| 22 | // |
| 23 | // foo() is called by main() in gcc_personality_test_helper.cxx. |
| 24 | // done_bar() is implemented in C++ and will throw an exception. |
| 25 | // main() will catch the exception and verify that the cleanup |
| 26 | // routines for foo() and bar() were called by the personality |
| 27 | // function. |
| 28 | // |
| 29 | |
| 30 | |
| 31 | void bar() |
| 32 | { |
| 33 | int x __attribute__((cleanup(bar_clean))) = 0; |
| 34 | register_bar_local(&x); |
| 35 | done_bar(); |
| 36 | } |
| 37 | |
| 38 | void foo() |
| 39 | { |
| 40 | int x __attribute__((cleanup(foo_clean))) = 0; |
| 41 | register_foo_local(&x); |
| 42 | bar(); |
| 43 | done_foo(); |
| 44 | } |
| 45 | |
| 46 | |