1 | // RUN: %clangxx_asan %s -o %t && %run %t |
2 | // RUN: %clangxx_asan %s -o %t -static-libstdc++ && %run %t |
3 | |
4 | // Investigate why it fails with NDK 21. |
5 | // UNSUPPORTED: android |
6 | |
7 | #include <stdio.h> |
8 | static volatile int zero = 0; |
9 | inline void pretend_to_do_something(void *x) { |
10 | __asm__ __volatile__("" : : "r" (x) : "memory" ); |
11 | } |
12 | |
13 | __attribute__((noinline)) |
14 | void ReallyThrow() { |
15 | fprintf(stderr, format: "ReallyThrow\n" ); |
16 | try { |
17 | if (zero == 0) |
18 | throw 42; |
19 | else if (zero == 1) |
20 | throw 1.; |
21 | } catch(double x) { |
22 | } |
23 | } |
24 | |
25 | __attribute__((noinline)) |
26 | void Throw() { |
27 | int a, b, c, d, e; |
28 | pretend_to_do_something(x: &a); |
29 | pretend_to_do_something(x: &b); |
30 | pretend_to_do_something(x: &c); |
31 | pretend_to_do_something(x: &d); |
32 | pretend_to_do_something(x: &e); |
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 | for (int i = 0; i < 100; i++) |
42 | ar[i] = i; |
43 | fprintf(stderr, format: "CheckStack stack = %p, %p\n" , ar, ar + 100); |
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 | |
55 | |