[ASan/Win tests] Don't generate debug info where it is not needed
[blocksruntime.git] / test / asan / TestCases / Windows / seh.cc
blob1fa1055e49f7f579626ce798b7d9a9cd89a31f62
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 // RUN: cl -c %s -Fo%t.obj
7 // RUN: %clangxx_asan -o %t.exe %s %t.obj
8 // RUN: %run %t.exe
10 #include <windows.h>
11 #include <assert.h>
12 #include <stdio.h>
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);
18 void ThrowAndCatch();
20 #if !defined(__clang__)
21 __declspec(noinline)
22 void Throw() {
23 int local, zero = 0;
24 fprintf(stderr, "Throw: %p\n", &local);
25 local = 5 / zero;
28 __declspec(noinline)
29 void ThrowAndCatch() {
30 int local;
31 __try {
32 Throw();
33 } __except(EXCEPTION_EXECUTE_HANDLER) {
34 fprintf(stderr, "__except: %p\n", &local);
37 #else
39 int main() {
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 ThrowAndCatch();
45 fprintf(stderr, "After: %p poisoned: %d\n", &x,
46 __asan_address_is_poisoned(x + 32));
47 // FIXME: Invert this assertion once we fix
48 // https://code.google.com/p/address-sanitizer/issues/detail?id=258
49 assert(!__asan_address_is_poisoned(x + 32));
51 #endif