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// Test that it works correctly even with ICF enabled.
6// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll -link /OPT:REF /OPT:ICF
7// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
8
9#include <stdio.h>
10#include <string.h>
11
12extern "C" __declspec(dllexport)
13int test_function() {
14  char buff[5] = "aaaa";
15
16  memset(buff, 'b', 5);
17  if (buff[2] != 'b')
18    return 2;
19  printf("Initial test OK\n");
20  fflush(0);
21// CHECK: Initial test OK
22
23  memset(buff, 'c', 6);
24// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
25// CHECK: WRITE of size 6 at [[ADDR]] thread T0
26// CHECK-NEXT:  __asan_memset
27// CHECK-NEXT:  test_function {{.*}}dll_intercept_memset.cc:[[@LINE-4]]
28// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame
29// CHECK-NEXT:  test_function {{.*}}dll_intercept_memset.cc
30// CHECK: 'buff' <== Memory access at offset {{.*}} overflows this variable
31  return 0;
32}
33