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// Clang doesn't support exceptions on Windows yet. 9// XFAIL: win32 10 11#include <stdio.h> 12static volatile int zero = 0; 13inline void pretend_to_do_something(void *x) { 14 __asm__ __volatile__("" : : "r" (x) : "memory"); 15} 16 17__attribute__((noinline, no_sanitize_address)) 18void ReallyThrow() { 19 fprintf(stderr, "ReallyThrow\n"); 20 if (zero == 0) 21 throw 42; 22} 23 24__attribute__((noinline)) 25void Throw() { 26 int a, b, c, d, e; 27 pretend_to_do_something(&a); 28 pretend_to_do_something(&b); 29 pretend_to_do_something(&c); 30 pretend_to_do_something(&d); 31 pretend_to_do_something(&e); 32 fprintf(stderr, "Throw stack = %p\n", &a); 33 ReallyThrow(); 34} 35 36__attribute__((noinline)) 37void CheckStack() { 38 int ar[100]; 39 pretend_to_do_something(ar); 40 for (int i = 0; i < 100; i++) 41 ar[i] = i; 42 fprintf(stderr, "CheckStack stack = %p, %p\n", ar, ar + 100); 43} 44 45int 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