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