Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t |
| 2 | // RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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(&buffer[0]); |
| 19 | __asan_poison_memory_region(buffer, 128); |
| 20 | should_not_crash(&buffer[192]); |
| 21 | __asan_unpoison_memory_region(buffer, 64); |
| 22 | should_not_crash(&buffer[32]); |
| 23 | |
| 24 | should_crash(&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 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 27 | // CHECK-NEXT: should_crash{{.*}}\dll_poison_unpoison.cc |
| 28 | // CHECK-NEXT: test_function{{.*}}\dll_poison_unpoison.cc:[[@LINE-4]] |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 29 | // CHECK-NEXT: main |
| 30 | // |
| 31 | // CHECK: [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 32 | // CHECK-NEXT: test_function{{.*}}\dll_poison_unpoison.cc |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 33 | // CHECK: 'buffer' <== Memory access at offset [[OFFSET]] is inside this variable |
| 34 | return 0; |
| 35 | } |