]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/test/asan/TestCases/throw_call_test.cc
New upstream version 1.12.0+dfsg1
[rustc.git] / src / compiler-rt / test / asan / TestCases / throw_call_test.cc
CommitLineData
1a4d82fc
JJ
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// Android builds with static libstdc++ by default.
6// XFAIL: android
7
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, no_sanitize_address))
15void ReallyThrow() {
16 fprintf(stderr, "ReallyThrow\n");
17 if (zero == 0)
18 throw 42;
19}
20
21__attribute__((noinline))
22void Throw() {
92a42be0 23 int a, b, c, d, e, f, g, h;
1a4d82fc
JJ
24 pretend_to_do_something(&a);
25 pretend_to_do_something(&b);
26 pretend_to_do_something(&c);
27 pretend_to_do_something(&d);
28 pretend_to_do_something(&e);
92a42be0
SL
29 pretend_to_do_something(&f);
30 pretend_to_do_something(&g);
31 pretend_to_do_something(&h);
1a4d82fc
JJ
32 fprintf(stderr, "Throw stack = %p\n", &a);
33 ReallyThrow();
34}
35
36__attribute__((noinline))
37void CheckStack() {
38 int ar[100];
39 pretend_to_do_something(ar);
92a42be0 40 fprintf(stderr, "CheckStack stack = %p, %p\n", ar, ar + 100);
1a4d82fc
JJ
41 for (int i = 0; i < 100; i++)
42 ar[i] = i;
1a4d82fc
JJ
43}
44
45int main(int argc, char** argv) {
46 try {
47 Throw();
48 } catch(int a) {
49 fprintf(stderr, "a = %d\n", a);
50 }
51 CheckStack();
52}