Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / throw_catch.cpp
blob2884e95f8a7e29e7b751420941e204e430006aa6
1 // RUN: %clangxx_asan -fsanitize-address-use-after-return=never -O %s -o %t && %run %t
3 #include <assert.h>
4 #include <stdio.h>
5 #include <sanitizer/asan_interface.h>
7 __attribute__((noinline))
8 void Throw() {
9 int local;
10 fprintf(stderr, "Throw: %p\n", &local);
11 throw 1;
14 __attribute__((noinline))
15 void ThrowAndCatch() {
16 int local;
17 try {
18 Throw();
19 } catch(...) {
20 fprintf(stderr, "Catch: %p\n", &local);
24 __attribute__((noinline))
25 void TestThrow() {
26 char x[32];
27 fprintf(stderr, "Before: %p poisoned: %d\n", &x,
28 __asan_address_is_poisoned(x + 32));
29 assert(__asan_address_is_poisoned(x + 32));
30 ThrowAndCatch();
31 fprintf(stderr, "After: %p poisoned: %d\n", &x,
32 __asan_address_is_poisoned(x + 32));
33 assert(!__asan_address_is_poisoned(x + 32));
36 __attribute__((noinline))
37 void TestThrowInline() {
38 char x[32];
39 fprintf(stderr, "Before: %p poisoned: %d\n", &x,
40 __asan_address_is_poisoned(x + 32));
41 assert(__asan_address_is_poisoned(x + 32));
42 try {
43 Throw();
44 } catch(...) {
45 fprintf(stderr, "Catch\n");
47 fprintf(stderr, "After: %p poisoned: %d\n", &x,
48 __asan_address_is_poisoned(x + 32));
49 assert(!__asan_address_is_poisoned(x + 32));
52 int main(int argc, char **argv) {
53 TestThrowInline();
54 TestThrow();