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