| 1 | // Test the handle_sigill option. |
| 2 | // |
| 3 | // RUN: %clangxx_asan %s -o %t && %env_asan_opts=handle_sigill=0 not --crash %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0 |
| 4 | // RUN: %clangxx_asan %s -o %t && %env_asan_opts=handle_sigill=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 |
| 5 | // REQUIRES: x86-target-arch && (!MSVC || asan-32-bits) |
| 6 | |
| 7 | #ifdef _WIN32 |
| 8 | #include <windows.h> |
| 9 | #endif |
| 10 | |
| 11 | // note: test is limited to i386 only ("asan-32-bits") when using "real" MSVC |
| 12 | // see the requires clause above |
| 13 | #if defined(_MSC_VER) && !defined(__clang__) |
| 14 | # define __builtin_trap() __asm ud2; |
| 15 | #endif |
| 16 | |
| 17 | int main(int argc, char **argv) { |
| 18 | #ifdef _WIN32 |
| 19 | // Sometimes on Windows this test generates a WER fault dialog. Suppress that. |
| 20 | UINT new_flags = SEM_FAILCRITICALERRORS | |
| 21 | SEM_NOGPFAULTERRORBOX | |
| 22 | SEM_NOOPENFILEERRORBOX; |
| 23 | // Preserve existing error mode, as discussed at |
| 24 | // http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx |
| 25 | UINT existing_flags = SetErrorMode(new_flags); |
| 26 | SetErrorMode(existing_flags | new_flags); |
| 27 | #endif |
| 28 | |
| 29 | if (argc) |
| 30 | __builtin_trap(); |
| 31 | // Unreachable code to avoid confusing the Windows unwinder. |
| 32 | #ifdef _WIN32 |
| 33 | SetErrorMode(0); |
| 34 | #endif |
| 35 | } |
| 36 | // CHECK0-NOT: ERROR: AddressSanitizer |
| 37 | // CHECK1: ERROR: AddressSanitizer: {{ILL|illegal-instruction}} on unknown address {{0x0*}} |
| 38 | |