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