| 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 | // MSVC doesn't support GCC style inline ASM |
| 6 | // UNSUPPORTED: msvc |
| 7 | |
| 8 | #include "defines.h" |
| 9 | #include <stdio.h> |
| 10 | static volatile int zero = 0; |
| 11 | inline void pretend_to_do_something(void *x) { |
| 12 | __asm__ __volatile__("" : : "r" (x) : "memory" ); |
| 13 | } |
| 14 | |
| 15 | __attribute__((noinline, no_sanitize_address)) |
| 16 | void ReallyThrow() { |
| 17 | fprintf(stderr, format: "ReallyThrow\n" ); |
| 18 | if (zero == 0) |
| 19 | throw 42; |
| 20 | } |
| 21 | |
| 22 | ATTRIBUTE_NOINLINE |
| 23 | void Throw() { |
| 24 | int a, b, c, d, e, f, g, h; |
| 25 | pretend_to_do_something(x: &a); |
| 26 | pretend_to_do_something(x: &b); |
| 27 | pretend_to_do_something(x: &c); |
| 28 | pretend_to_do_something(x: &d); |
| 29 | pretend_to_do_something(x: &e); |
| 30 | pretend_to_do_something(x: &f); |
| 31 | pretend_to_do_something(x: &g); |
| 32 | pretend_to_do_something(x: &h); |
| 33 | fprintf(stderr, format: "Throw stack = %p\n" , &a); |
| 34 | ReallyThrow(); |
| 35 | } |
| 36 | |
| 37 | ATTRIBUTE_NOINLINE |
| 38 | void CheckStack() { |
| 39 | int ar[100]; |
| 40 | pretend_to_do_something(x: ar); |
| 41 | fprintf(stderr, format: "CheckStack stack = %p, %p\n" , ar, ar + 100); |
| 42 | for (int i = 0; i < 100; i++) |
| 43 | ar[i] = i; |
| 44 | } |
| 45 | |
| 46 | int main(int argc, char** argv) { |
| 47 | try { |
| 48 | Throw(); |
| 49 | } catch(int a) { |
| 50 | fprintf(stderr, format: "a = %d\n" , a); |
| 51 | } |
| 52 | CheckStack(); |
| 53 | } |
| 54 | |