1// RUN: %clang_cl_asan %Od %s %Fe%t
2// RUN: env ASAN_OPTIONS=handle_segv=0 %run %t 2>&1 | FileCheck %s --check-prefix=USER
3// RUN: env ASAN_OPTIONS=handle_segv=1 not %run %t 2>&1 | FileCheck %s --check-prefix=ASAN
4// Test the default.
5// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=ASAN
6
7// This test exits zero when its unhandled exception filter is set. ASan should
8// not disturb it when handle_segv=0.
9
10// USER: in main
11// USER: in SEHHandler
12
13// ASAN: in main
14// ASAN: ERROR: AddressSanitizer: access-violation
15
16#include <windows.h>
17#include <stdio.h>
18
19static long WINAPI SEHHandler(EXCEPTION_POINTERS *info) {
20 DWORD exception_code = info->ExceptionRecord->ExceptionCode;
21 if (exception_code == EXCEPTION_ACCESS_VIOLATION) {
22 fprintf(stderr, "in SEHHandler\n");
23 fflush(stderr);
24 TerminateProcess(GetCurrentProcess(), 0);
25 }
26 return EXCEPTION_CONTINUE_SEARCH;
27}
28
29int main() {
30 SetUnhandledExceptionFilter(SEHHandler);
31 fprintf(stderr, format: "in main\n");
32 fflush(stderr);
33
34 volatile int *p = nullptr;
35 *p = 42;
36}
37

source code of compiler-rt/test/asan/TestCases/Windows/user-exception.cpp