blob: 50cf6ddba8d61a72b0804eb47d08730653575d09 [file] [log] [blame]
Stephen Hines6d186232014-11-26 17:56:19 -08001// 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.
21extern "C" bool __asan_address_is_poisoned(void *p);
22
23void ThrowAndCatch();
24
25#if !defined(__clang__)
26__declspec(noinline)
27void Throw() {
28 int local, zero = 0;
29 fprintf(stderr, "Throw: %p\n", &local);
30 local = 5 / zero;
31}
32
33__declspec(noinline)
34void 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
44int 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