brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 9a29bee Raw
51 lines · cpp
1// RUN: %clang_cl_asan -Od %p/../dll_host.cpp -Fe%t2//3// Check both -GS and -GS- builds:4// RUN: %clang_cl_asan -GS  -LD -Od %s -Fe%t.dll5// RUN: %run %t %t.dll6//7// RUN: %clang_cl_asan -GS- -LD -Od %s -Fe%t.dll8// RUN: %run %t %t.dll9 10#include <windows.h>11#include <assert.h>12#include <stdio.h>13 14// Should just "#include <sanitizer/asan_interface.h>" when C++ exceptions are15// supported and we don't need to use CL.16extern "C" bool __asan_address_is_poisoned(void *p);17 18void ThrowAndCatch();19 20__declspec(noinline)21void Throw() {22  int local, zero = 0;23  fprintf(stderr, "Throw:  %p\n", &local);24  local = 5 / zero;25}26 27__declspec(noinline)28void ThrowAndCatch() {29  int local;30  __try {31    Throw();32  } __except(EXCEPTION_EXECUTE_HANDLER) {33    fprintf(stderr, "__except:  %p\n", &local);34  }35}36 37extern "C" __declspec(dllexport)38int 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 fix47  // https://code.google.com/p/address-sanitizer/issues/detail?id=25848  assert(!__asan_address_is_poisoned(x + 32));49  return 0;50}51