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 // Android builds with static libstdc++ by default. 6 // XFAIL: android 7 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"); 12 } 13 14 __attribute__((noinline, no_sanitize_address)) 15 void ReallyThrow() { 16 fprintf(stderr, "ReallyThrow\n"); 17 if (zero == 0) 18 throw 42; 19 } 20 21 __attribute__((noinline)) 22 void Throw() { 23 int a, b, c, d, e, f, g, h; 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 pretend_to_do_something(&f); 30 pretend_to_do_something(&g); 31 pretend_to_do_something(&h); 32 fprintf(stderr, "Throw stack = %p\n", &a); 33 ReallyThrow(); 34 } 35 36 __attribute__((noinline)) 37 void CheckStack() { 38 int ar[100]; 39 pretend_to_do_something(ar); 40 fprintf(stderr, "CheckStack stack = %p, %p\n", ar, ar + 100); 41 for (int i = 0; i < 100; i++) 42 ar[i] = i; 43 } 44 45 int main(int argc, char** argv) { 46 try { 47 Throw(); 48 } catch(int a) { 49 fprintf(stderr, "a = %d\n", a); 50 } 51 CheckStack(); 52 } 53