1 // RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t 2 // 3 // Check both -GS and -GS- builds: 4 // RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll 5 // RUN: %run %t %t.dll 6 // 7 // RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll 8 // RUN: %run %t %t.dll 9 10 #include <windows.h> 11 #include <assert.h> 12 #include <stdio.h> 13 14 // Should just "#include <sanitizer/asan_interface.h>" when C++ exceptions are 15 // supported and we don't need to use CL. 16 extern "C" bool __asan_address_is_poisoned(void *p); 17 18 void ThrowAndCatch(); 19 20 __declspec(noinline) 21 void Throw() { 22 int local, zero = 0; 23 fprintf(stderr, "Throw: %p\n", &local); 24 local = 5 / zero; 25 } 26 27 __declspec(noinline) 28 void ThrowAndCatch() { 29 int local; 30 __try { 31 Throw(); 32 } __except(EXCEPTION_EXECUTE_HANDLER) { 33 fprintf(stderr, "__except: %p\n", &local); 34 } 35 } 36 37 extern "C" __declspec(dllexport) 38 int test_function() { 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 ThrowAndCatch(); 44 fprintf(stderr, "After: %p poisoned: %d\n", &x, 45 __asan_address_is_poisoned(x + 32)); 46 // FIXME: Invert this assertion once we fix 47 // https://code.google.com/p/address-sanitizer/issues/detail?id=258 48 assert(!__asan_address_is_poisoned(x + 32)); 49 return 0; 50 } 51