Home | History | Annotate | Download | only in Unit
      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 
     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 
     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  */
     30 
     31 void bar() {
     32     int x __attribute__((cleanup(bar_clean))) = 0;
     33     register_bar_local(&x);
     34     done_bar();
     35 }
     36 
     37 void foo() {
     38     int x __attribute__((cleanup(foo_clean))) = 0;
     39     register_foo_local(&x);
     40     bar();
     41     done_foo();
     42 }
     43