aboutsummaryrefslogtreecommitdiff
path: root/test/builtins/Unit/gcc_personality_test_helper.cxx
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-01-07 19:55:37 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-01-07 19:55:37 +0000
commitca9211ecdede9bdedb812b2243a4abdb8dacd1b9 (patch)
tree9b19e801150082c33e9152275829a6ce90614b55 /test/builtins/Unit/gcc_personality_test_helper.cxx
parent8ef50bf3d1c287b5013c3168de77a462dfce3495 (diff)
downloadsrc-ca9211ecdede9bdedb812b2243a4abdb8dacd1b9.tar.gz
src-ca9211ecdede9bdedb812b2243a4abdb8dacd1b9.zip
Import compiler-rt trunk r224034.vendor/compiler-rt/compiler-rt-r224034
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=276789 svn path=/vendor/compiler-rt/compiler-rt-r224034/; revision=276790; tag=vendor/compiler-rt/compiler-rt-r224034
Diffstat (limited to 'test/builtins/Unit/gcc_personality_test_helper.cxx')
-rw-r--r--test/builtins/Unit/gcc_personality_test_helper.cxx85
1 files changed, 85 insertions, 0 deletions
diff --git a/test/builtins/Unit/gcc_personality_test_helper.cxx b/test/builtins/Unit/gcc_personality_test_helper.cxx
new file mode 100644
index 000000000000..7d1ddfb5d960
--- /dev/null
+++ b/test/builtins/Unit/gcc_personality_test_helper.cxx
@@ -0,0 +1,85 @@
+//===-- gcc_personality_test_helper.cxx -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdlib.h>
+#include <stdio.h>
+
+extern "C" {
+ extern void foo_clean(void* x);
+ extern void bar_clean(void* x);
+ extern void register_foo_local(int* x);
+ extern void register_bar_local(int* x);
+ extern void done_foo();
+ extern void done_bar();
+ extern void foo();
+}
+
+static int* foo_x = NULL;
+void register_foo_local(int* x)
+{
+ foo_x = x;
+}
+
+static int* bar_x = NULL;
+void register_bar_local(int* x)
+{
+ bar_x = x;
+}
+
+static bool foo_clean_called = false;
+void foo_clean(void* x)
+{
+ if ( foo_x == NULL )
+ abort();
+ if ( foo_x != (int*)x)
+ abort();
+ foo_clean_called = true;
+}
+
+static bool bar_clean_called = false;
+void bar_clean(void* x)
+{
+ if ( bar_x == NULL )
+ abort();
+ if ( bar_x != (int*)x)
+ abort();
+ bar_clean_called = true;
+}
+
+void done_foo()
+{
+}
+
+void done_bar()
+{
+ throw "done";
+}
+
+
+//
+// foo() is in gcc_personality_test.c and calls bar() which
+// calls done_bar() which throws an exception.
+// main() will catch the exception and verify that the cleanup
+// routines for foo() and bar() were called by the personality
+// function.
+//
+int main()
+{
+ try {
+ foo();
+ }
+ catch(...) {
+ if ( !foo_clean_called )
+ abort();
+ if ( !bar_clean_called )
+ abort();
+ return 0;
+ }
+ abort();
+}