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>
9static volatile int zero = 0;
10inline void pretend_to_do_something(void *x) {
11 __asm__ __volatile__("" : : "r" (x) : "memory");
12}
13
14__attribute__((noinline))
15void 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))
27void 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
38ATTRIBUTE_NOINLINE
39void 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
47int 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

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

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