Edward O'Callaghan | cc75801 | 2009-10-17 10:19:32 +0000 | [diff] [blame] | 1 | /* ===-- gcc_personality_test.c - Tests __gcc_personality_v0 -------------=== |
| 2 | * |
| 3 | * The LLVM Compiler Infrastructure |
| 4 | * |
Howard Hinnant | 9ad441f | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 5 | * This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | * Source Licenses. See LICENSE.TXT for details. |
Edward O'Callaghan | cc75801 | 2009-10-17 10:19:32 +0000 | [diff] [blame] | 7 | * |
| 8 | * ===----------------------------------------------------------------------=== |
| 9 | */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 10 | |
| 11 | |
| 12 | #include <stdlib.h> |
| 13 | #include <stdio.h> |
| 14 | |
| 15 | extern void foo_clean(void* x); |
| 16 | extern void bar_clean(void* x); |
| 17 | extern void register_foo_local(int* x); |
| 18 | extern void register_bar_local(int* x); |
| 19 | extern void done_foo(); |
| 20 | extern void done_bar(); |
| 21 | |
| 22 | |
Edward O'Callaghan | cc75801 | 2009-10-17 10:19:32 +0000 | [diff] [blame] | 23 | /* |
| 24 | * foo() is called by main() in gcc_personality_test_helper.cxx. |
| 25 | * done_bar() is implemented in C++ and will throw an exception. |
| 26 | * main() will catch the exception and verify that the cleanup |
| 27 | * routines for foo() and bar() were called by the personality |
| 28 | * function. |
| 29 | */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 30 | |
Edward O'Callaghan | cc75801 | 2009-10-17 10:19:32 +0000 | [diff] [blame] | 31 | void bar() { |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 32 | int x __attribute__((cleanup(bar_clean))) = 0; |
| 33 | register_bar_local(&x); |
| 34 | done_bar(); |
| 35 | } |
| 36 | |
Edward O'Callaghan | cc75801 | 2009-10-17 10:19:32 +0000 | [diff] [blame] | 37 | void foo() { |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 38 | int x __attribute__((cleanup(foo_clean))) = 0; |
| 39 | register_foo_local(&x); |
| 40 | bar(); |
| 41 | done_foo(); |
| 42 | } |