1// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
2// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
3// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
4
5#include <sanitizer/asan_interface.h>
6
7void should_not_crash(volatile char *c) {
8  *c = 42;
9}
10
11void should_crash(volatile char *c) {
12  *c = 42;
13}
14
15extern "C" __declspec(dllexport)
16int 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
27// CHECK-NEXT: should_crash{{.*}}\dll_poison_unpoison.cc
28// CHECK-NEXT: test_function{{.*}}\dll_poison_unpoison.cc:[[@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.cc
33// CHECK: 'buffer' <== Memory access at offset [[OFFSET]] is inside this variable
34  return 0;
35}
36