Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 1 | // Clang doesn't support SEH on Windows yet, so for the time being we |
| 2 | // build this program in two parts: the code with SEH is built with CL, |
| 3 | // the rest is built with Clang. This represents the typical scenario when we |
| 4 | // build a large project using "clang-cl -fallback -fsanitize=address". |
| 5 | // |
| 6 | // Check both -GS and -GS- builds: |
| 7 | // RUN: cl -c %s -Fo%t.obj |
| 8 | // RUN: %clangxx_asan -o %t.exe %s %t.obj |
| 9 | // RUN: %run %t.exe |
| 10 | // |
| 11 | // RUN: cl -GS- -c %s -Fo%t.obj |
| 12 | // RUN: %clangxx_asan -o %t.exe %s %t.obj |
| 13 | // RUN: %run %t.exe |
| 14 | |
| 15 | #include <windows.h> |
| 16 | #include <assert.h> |
| 17 | #include <stdio.h> |
| 18 | |
| 19 | // Should just "#include <sanitizer/asan_interface.h>" when C++ exceptions are |
| 20 | // supported and we don't need to use CL. |
| 21 | extern "C" bool __asan_address_is_poisoned(void *p); |
| 22 | |
| 23 | void ThrowAndCatch(); |
| 24 | |
| 25 | #if !defined(__clang__) |
| 26 | __declspec(noinline) |
| 27 | void Throw() { |
| 28 | int local, zero = 0; |
| 29 | fprintf(stderr, "Throw: %p\n", &local); |
| 30 | local = 5 / zero; |
| 31 | } |
| 32 | |
| 33 | __declspec(noinline) |
| 34 | void ThrowAndCatch() { |
| 35 | int local; |
| 36 | __try { |
| 37 | Throw(); |
| 38 | } __except(EXCEPTION_EXECUTE_HANDLER) { |
| 39 | fprintf(stderr, "__except: %p\n", &local); |
| 40 | } |
| 41 | } |
| 42 | #else |
| 43 | |
| 44 | int main() { |
| 45 | char x[32]; |
| 46 | fprintf(stderr, "Before: %p poisoned: %d\n", &x, |
| 47 | __asan_address_is_poisoned(x + 32)); |
| 48 | assert(__asan_address_is_poisoned(x + 32)); |
| 49 | ThrowAndCatch(); |
| 50 | fprintf(stderr, "After: %p poisoned: %d\n", &x, |
| 51 | __asan_address_is_poisoned(x + 32)); |
| 52 | // FIXME: Invert this assertion once we fix |
| 53 | // https://code.google.com/p/address-sanitizer/issues/detail?id=258 |
| 54 | assert(!__asan_address_is_poisoned(x + 32)); |
| 55 | } |
| 56 | #endif |