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>
6static volatile int zero = 0;
7inline void pretend_to_do_something(void *x) {
8 __asm__ __volatile__("" : : "r" (x) : "memory");
9}
10
11__attribute__((noinline, no_sanitize_address))
12void ReallyThrow() {
13 fprintf(stderr, format: "ReallyThrow\n");
14 if (zero == 0)
15 throw 42;
16}
17
18__attribute__((noinline))
19void 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))
34void 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
42int 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

source code of compiler-rt/test/asan/TestCases/throw_call_test.cpp