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