Move ASan lit-tests under test/asan
[blocksruntime.git] / test / asan / TestCases / throw_call_test.cc
blob3a97a94b630419515b4829af5999d7d680752a4b
1 // RUN: %clangxx_asan %s -o %t && %t
2 // http://code.google.com/p/address-sanitizer/issues/detail?id=147 (not fixed).
3 // BROKEN: %clangxx_asan %s -o %t -static-libstdc++ && %t
4 //
5 // Android builds with static libstdc++ by default.
6 // XFAIL: android
8 #include <stdio.h>
9 static volatile int zero = 0;
10 inline void pretend_to_do_something(void *x) {
11 __asm__ __volatile__("" : : "r" (x) : "memory");
14 __attribute__((noinline, no_sanitize_address))
15 void ReallyThrow() {
16 fprintf(stderr, "ReallyThrow\n");
17 if (zero == 0)
18 throw 42;
21 __attribute__((noinline))
22 void Throw() {
23 int a, b, c, d, e;
24 pretend_to_do_something(&a);
25 pretend_to_do_something(&b);
26 pretend_to_do_something(&c);
27 pretend_to_do_something(&d);
28 pretend_to_do_something(&e);
29 fprintf(stderr, "Throw stack = %p\n", &a);
30 ReallyThrow();
33 __attribute__((noinline))
34 void CheckStack() {
35 int ar[100];
36 pretend_to_do_something(ar);
37 for (int i = 0; i < 100; i++)
38 ar[i] = i;
39 fprintf(stderr, "CheckStack stack = %p, %p\n", ar, ar + 100);
42 int main(int argc, char** argv) {
43 try {
44 Throw();
45 } catch(int a) {
46 fprintf(stderr, "a = %d\n", a);
48 CheckStack();