1 // RUN: %clangxx_asan -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, "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, "Catch: %p\n", &local); 21 } 22 } 23 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 // FIXME: Invert this assertion once we fix 34 // https://code.google.com/p/address-sanitizer/issues/detail?id=258 35 // This assertion works only w/o UAR. 36 if (!__asan_get_current_fake_stack()) 37 assert(!__asan_address_is_poisoned(x + 32)); 38 } 39 40 __attribute__((noinline)) 41 void TestThrowInline() { 42 char x[32]; 43 fprintf(stderr, "Before: %p poisoned: %d\n", &x, 44 __asan_address_is_poisoned(x + 32)); 45 assert(__asan_address_is_poisoned(x + 32)); 46 try { 47 Throw(); 48 } catch(...) { 49 fprintf(stderr, "Catch\n"); 50 } 51 fprintf(stderr, "After: %p poisoned: %d\n", &x, 52 __asan_address_is_poisoned(x + 32)); 53 // FIXME: Invert this assertion once we fix 54 // https://code.google.com/p/address-sanitizer/issues/detail?id=258 55 // This assertion works only w/o UAR. 56 if (!__asan_get_current_fake_stack()) 57 assert(!__asan_address_is_poisoned(x + 32)); 58 } 59 60 int main(int argc, char **argv) { 61 TestThrowInline(); 62 TestThrow(); 63 } 64