1 // RUN: %clangxx_asan %s -o %t && %run %t
2 // http://code.google.com/p/address-sanitizer/issues/detail?id=147 (not fixed).
3 // BROKEN: %clangxx_asan %s -o %t -static-libstdc++ && %run %t
4 
5 #include <stdio.h>
6 static volatile int zero = 0;
pretend_to_do_something(void * x)7 inline void pretend_to_do_something(void *x) {
8   __asm__ __volatile__("" : : "r" (x) : "memory");
9 }
10 
11 __attribute__((noinline, no_sanitize_address))
ReallyThrow()12 void ReallyThrow() {
13   fprintf(stderr, "ReallyThrow\n");
14   if (zero == 0)
15     throw 42;
16 }
17 
18 __attribute__((noinline))
Throw()19 void Throw() {
20   int a, b, c, d, e, f, g, h;
21   pretend_to_do_something(&a);
22   pretend_to_do_something(&b);
23   pretend_to_do_something(&c);
24   pretend_to_do_something(&d);
25   pretend_to_do_something(&e);
26   pretend_to_do_something(&f);
27   pretend_to_do_something(&g);
28   pretend_to_do_something(&h);
29   fprintf(stderr, "Throw stack = %p\n", &a);
30   ReallyThrow();
31 }
32 
33 __attribute__((noinline))
CheckStack()34 void CheckStack() {
35   int ar[100];
36   pretend_to_do_something(ar);
37   fprintf(stderr, "CheckStack stack = %p, %p\n", ar, ar + 100);
38   for (int i = 0; i < 100; i++)
39     ar[i] = i;
40 }
41 
main(int argc,char ** argv)42 int main(int argc, char** argv) {
43   try {
44     Throw();
45   } catch(int a) {
46     fprintf(stderr, "a = %d\n", a);
47   }
48   CheckStack();
49 }
50