blob: f9598c697eb692a9198efe8c8ddfbd1e016e7782 [file] [log] [blame]
Edward O'Callaghancc758012009-10-17 10:19:32 +00001/* ===-- gcc_personality_test.c - Tests __gcc_personality_v0 -------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant9ad441f2010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghancc758012009-10-17 10:19:32 +00007 *
8 * ===----------------------------------------------------------------------===
9 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000010
11
12#include <stdlib.h>
13#include <stdio.h>
14
15extern void foo_clean(void* x);
16extern void bar_clean(void* x);
17extern void register_foo_local(int* x);
18extern void register_bar_local(int* x);
19extern void done_foo();
20extern void done_bar();
21
22
Edward O'Callaghancc758012009-10-17 10:19:32 +000023/*
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 Dunbarb3a69012009-06-26 16:47:03 +000030
Edward O'Callaghancc758012009-10-17 10:19:32 +000031void bar() {
Daniel Dunbarb3a69012009-06-26 16:47:03 +000032 int x __attribute__((cleanup(bar_clean))) = 0;
33 register_bar_local(&x);
34 done_bar();
35}
36
Edward O'Callaghancc758012009-10-17 10:19:32 +000037void foo() {
Daniel Dunbarb3a69012009-06-26 16:47:03 +000038 int x __attribute__((cleanup(foo_clean))) = 0;
39 register_foo_local(&x);
40 bar();
41 done_foo();
42}