summaryrefslogtreecommitdiff
path: root/test/asan/TestCases/throw_call_test.cc
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2014-02-14 14:06:10 +0000
committerAlexey Samsonov <samsonov@google.com>2014-02-14 14:06:10 +0000
commitba2d0d7b386f38c97eee11749f2fc75449c2b253 (patch)
tree645ce9b32dc3f7727d3bac94f8c3387d051b9c01 /test/asan/TestCases/throw_call_test.cc
parent5811f0e1e955866b76b0d9ebeccd2e4755c1dac8 (diff)
Move ASan lit-tests under test/asan
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@201413 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/asan/TestCases/throw_call_test.cc')
-rw-r--r--test/asan/TestCases/throw_call_test.cc49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/asan/TestCases/throw_call_test.cc b/test/asan/TestCases/throw_call_test.cc
new file mode 100644
index 000000000..3a97a94b6
--- /dev/null
+++ b/test/asan/TestCases/throw_call_test.cc
@@ -0,0 +1,49 @@
+// RUN: %clangxx_asan %s -o %t && %t
+// http://code.google.com/p/address-sanitizer/issues/detail?id=147 (not fixed).
+// BROKEN: %clangxx_asan %s -o %t -static-libstdc++ && %t
+//
+// Android builds with static libstdc++ by default.
+// XFAIL: android
+
+#include <stdio.h>
+static volatile int zero = 0;
+inline void pretend_to_do_something(void *x) {
+ __asm__ __volatile__("" : : "r" (x) : "memory");
+}
+
+__attribute__((noinline, no_sanitize_address))
+void ReallyThrow() {
+ fprintf(stderr, "ReallyThrow\n");
+ if (zero == 0)
+ throw 42;
+}
+
+__attribute__((noinline))
+void Throw() {
+ int a, b, c, d, e;
+ pretend_to_do_something(&a);
+ pretend_to_do_something(&b);
+ pretend_to_do_something(&c);
+ pretend_to_do_something(&d);
+ pretend_to_do_something(&e);
+ fprintf(stderr, "Throw stack = %p\n", &a);
+ ReallyThrow();
+}
+
+__attribute__((noinline))
+void CheckStack() {
+ int ar[100];
+ pretend_to_do_something(ar);
+ for (int i = 0; i < 100; i++)
+ ar[i] = i;
+ fprintf(stderr, "CheckStack stack = %p, %p\n", ar, ar + 100);
+}
+
+int main(int argc, char** argv) {
+ try {
+ Throw();
+ } catch(int a) {
+ fprintf(stderr, "a = %d\n", a);
+ }
+ CheckStack();
+}