[ASan/Win tests] Don't generate debug info where it is not needed
[blocksruntime.git] / test / asan / TestCases / Windows / dll_seh.cc
blob62ec055c448ec391fa43e99c4258c705838d3e64
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: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
7 // RUN: cl -LD -c %s -Fo%t.obj
8 // RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll %t.obj
9 // RUN: %run %t %t.dll
11 #include <windows.h>
12 #include <assert.h>
13 #include <stdio.h>
15 // Should just "#include <sanitizer/asan_interface.h>" when C++ exceptions are
16 // supported and we don't need to use CL.
17 extern "C" bool __asan_address_is_poisoned(void *p);
19 void ThrowAndCatch();
21 #if !defined(__clang__)
22 __declspec(noinline)
23 void Throw() {
24 int local, zero = 0;
25 fprintf(stderr, "Throw: %p\n", &local);
26 local = 5 / zero;
29 __declspec(noinline)
30 void ThrowAndCatch() {
31 int local;
32 __try {
33 Throw();
34 } __except(EXCEPTION_EXECUTE_HANDLER) {
35 fprintf(stderr, "__except: %p\n", &local);
38 #else
40 extern "C" __declspec(dllexport)
41 int test_function() {
42 char x[32];
43 fprintf(stderr, "Before: %p poisoned: %d\n", &x,
44 __asan_address_is_poisoned(x + 32));
45 assert(__asan_address_is_poisoned(x + 32));
46 ThrowAndCatch();
47 fprintf(stderr, "After: %p poisoned: %d\n", &x,
48 __asan_address_is_poisoned(x + 32));
49 // FIXME: Invert this assertion once we fix
50 // https://code.google.com/p/address-sanitizer/issues/detail?id=258
51 assert(!__asan_address_is_poisoned(x + 32));
52 return 0;
54 #endif