1 | // RUN: %clangxx_asan -fsanitize-address-use-after-return=never -O %s -o %t && %run %t |
2 | |
3 | #include <assert.h> |
4 | #include <stdio.h> |
5 | #include <sanitizer/asan_interface.h> |
6 | |
7 | __attribute__((noinline)) |
8 | void Throw() { |
9 | int local; |
10 | fprintf(stderr, format: "Throw: %p\n" , &local); |
11 | throw 1; |
12 | } |
13 | |
14 | __attribute__((noinline)) |
15 | void ThrowAndCatch() { |
16 | int local; |
17 | try { |
18 | Throw(); |
19 | } catch(...) { |
20 | fprintf(stderr, format: "Catch: %p\n" , &local); |
21 | } |
22 | } |
23 | |
24 | __attribute__((noinline)) |
25 | void TestThrow() { |
26 | char x[32]; |
27 | fprintf(stderr, format: "Before: %p poisoned: %d\n" , &x, |
28 | __asan_address_is_poisoned(addr: x + 32)); |
29 | assert(__asan_address_is_poisoned(x + 32)); |
30 | ThrowAndCatch(); |
31 | fprintf(stderr, format: "After: %p poisoned: %d\n" , &x, |
32 | __asan_address_is_poisoned(addr: x + 32)); |
33 | assert(!__asan_address_is_poisoned(x + 32)); |
34 | } |
35 | |
36 | __attribute__((noinline)) |
37 | void TestThrowInline() { |
38 | char x[32]; |
39 | fprintf(stderr, format: "Before: %p poisoned: %d\n" , &x, |
40 | __asan_address_is_poisoned(addr: x + 32)); |
41 | assert(__asan_address_is_poisoned(x + 32)); |
42 | try { |
43 | Throw(); |
44 | } catch(...) { |
45 | fprintf(stderr, format: "Catch\n" ); |
46 | } |
47 | fprintf(stderr, format: "After: %p poisoned: %d\n" , &x, |
48 | __asan_address_is_poisoned(addr: x + 32)); |
49 | assert(!__asan_address_is_poisoned(x + 32)); |
50 | } |
51 | |
52 | int main(int argc, char **argv) { |
53 | TestThrowInline(); |
54 | TestThrow(); |
55 | } |
56 | |