| 1 | // RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t |
| 2 | // RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll |
| 3 | // RUN: not %run %t %t.dll 2>&1 | FileCheck %s |
| 4 | |
| 5 | #include <sanitizer/asan_interface.h> |
| 6 | |
| 7 | void should_not_crash(volatile char *c) { |
| 8 | *c = 42; |
| 9 | } |
| 10 | |
| 11 | void should_crash(volatile char *c) { |
| 12 | *c = 42; |
| 13 | } |
| 14 | |
| 15 | extern "C" __declspec(dllexport) |
| 16 | int test_function() { |
| 17 | char buffer[256]; |
| 18 | should_not_crash(c: &buffer[0]); |
| 19 | __asan_poison_memory_region(addr: buffer, size: 128); |
| 20 | should_not_crash(c: &buffer[192]); |
| 21 | __asan_unpoison_memory_region(addr: buffer, size: 64); |
| 22 | should_not_crash(c: &buffer[32]); |
| 23 | |
| 24 | should_crash(c: &buffer[96]); |
| 25 | // CHECK: AddressSanitizer: use-after-poison on address [[ADDR:0x[0-9a-f]+]] |
| 26 | // CHECK-NEXT: WRITE of size 1 at [[ADDR]] thread T0 |
| 27 | // CHECK-NEXT: should_crash{{.*[\\/]}}dll_poison_unpoison.cpp |
| 28 | // CHECK-NEXT: test_function{{.*[\\/]}}dll_poison_unpoison.cpp:[[@LINE-4]] |
| 29 | // CHECK-NEXT: main |
| 30 | // |
| 31 | // CHECK: [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame |
| 32 | // CHECK-NEXT: test_function{{.*[\\/]}}dll_poison_unpoison.cpp |
| 33 | // CHECK: 'buffer'{{.*}} <== Memory access at offset [[OFFSET]] is inside this variable |
| 34 | return 0; |
| 35 | } |
| 36 | |