brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · f3c7e1a Raw
59 lines · cpp
1// Make sure that ASan works with SEH in both Clang and MSVC. MSVC uses a2// different EH personality depending on the -GS setting, so test both -GS+ and3// -GS-.4//5// RUN: cl /EHa %MD -c %s -Fo%t.obj -DCOMPILE_SEH6// RUN: %clangxx_asan -o %t.exe %s %t.obj -DCOMPILE_MAIN7// RUN: %run %t.exe8//9// RUN: cl /EHa %MD -GS- -c %s -Fo%t.obj -DCOMPILE_SEH10// RUN: %clangxx_asan -o %t.exe %s %t.obj -DCOMPILE_MAIN11// RUN: %run %t.exe12//13// RUN: %clang_cl_asan /EHa %MD %s -DCOMPILE_SEH -Fe%t.exe -DCOMPILE_MAIN14// RUN: %run %t.exe15 16#include <windows.h>17#include <assert.h>18#include <stdio.h>19 20// Should just "#include <sanitizer/asan_interface.h>" when C++ exceptions are21// supported and we don't need to use CL.22extern "C" bool __asan_address_is_poisoned(void *p);23 24void ThrowAndCatch();25 26#if defined(COMPILE_SEH)27__declspec(noinline)28void Throw() {29  int local, zero = 0;30  fprintf(stderr, "Throw:  %p\n", &local);31  local = 5 / zero;32}33 34__declspec(noinline)35void ThrowAndCatch() {36  int local;37  __try {38    Throw();39  } __except(EXCEPTION_EXECUTE_HANDLER) {40    fprintf(stderr, "__except:  %p\n", &local);41  }42}43#endif44 45#if defined(COMPILE_MAIN)46int main() {47  char x[32];48  fprintf(stderr, "Before: %p poisoned: %d\n", &x,49          __asan_address_is_poisoned(x + 32));50  assert(__asan_address_is_poisoned(x + 32));51  ThrowAndCatch();52  fprintf(stderr, "After:  %p poisoned: %d\n",  &x,53          __asan_address_is_poisoned(x + 32));54  // FIXME: Invert this assertion once we fix55  // https://code.google.com/p/address-sanitizer/issues/detail?id=25856  assert(!__asan_address_is_poisoned(x + 32));57}58#endif59