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))
8void Throw() {
9 int local;
10 fprintf(stderr, format: "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, format: "Catch: %p\n", &local);
21 }
22}
23
24__attribute__((noinline))
25void 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))
37void 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
52int main(int argc, char **argv) {
53 TestThrowInline();
54 TestThrow();
55}
56

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