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