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