]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/test/asan/TestCases/throw_catch.cc
New upstream version 1.19.0+dfsg3
[rustc.git] / src / compiler-rt / test / asan / TestCases / throw_catch.cc
CommitLineData
1a4d82fc
JJ
1// RUN: %clangxx_asan -O %s -o %t && %run %t
2
3#include <assert.h>
1a4d82fc 4#include <stdio.h>
1a4d82fc
JJ
5#include <sanitizer/asan_interface.h>
6
7__attribute__((noinline))
8void Throw() {
9 int local;
10 fprintf(stderr, "Throw: %p\n", &local);
11 throw 1;
12}
13
14__attribute__((noinline))
15void ThrowAndCatch() {
16 int local;
17 try {
18 Throw();
19 } catch(...) {
20 fprintf(stderr, "Catch: %p\n", &local);
21 }
22}
23
24void TestThrow() {
25 char x[32];
26 fprintf(stderr, "Before: %p poisoned: %d\n", &x,
27 __asan_address_is_poisoned(x + 32));
92a42be0 28 assert(__asan_address_is_poisoned(x + 32));
1a4d82fc
JJ
29 ThrowAndCatch();
30 fprintf(stderr, "After: %p poisoned: %d\n", &x,
31 __asan_address_is_poisoned(x + 32));
32 // FIXME: Invert this assertion once we fix
33 // https://code.google.com/p/address-sanitizer/issues/detail?id=258
92a42be0
SL
34 // This assertion works only w/o UAR.
35 if (!__asan_get_current_fake_stack())
36 assert(!__asan_address_is_poisoned(x + 32));
1a4d82fc
JJ
37}
38
39void TestThrowInline() {
40 char x[32];
41 fprintf(stderr, "Before: %p poisoned: %d\n", &x,
42 __asan_address_is_poisoned(x + 32));
92a42be0 43 assert(__asan_address_is_poisoned(x + 32));
1a4d82fc
JJ
44 try {
45 Throw();
46 } catch(...) {
47 fprintf(stderr, "Catch\n");
48 }
49 fprintf(stderr, "After: %p poisoned: %d\n", &x,
50 __asan_address_is_poisoned(x + 32));
51 // FIXME: Invert this assertion once we fix
52 // https://code.google.com/p/address-sanitizer/issues/detail?id=258
92a42be0
SL
53 // This assertion works only w/o UAR.
54 if (!__asan_get_current_fake_stack())
55 assert(!__asan_address_is_poisoned(x + 32));
1a4d82fc
JJ
56}
57
58int main(int argc, char **argv) {
1a4d82fc 59 TestThrowInline();
92a42be0 60 TestThrow();
1a4d82fc 61}