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
12 extern "C" __declspec(dllexport)
test_function()13 int test_function() {
14 char buff1[6] = "Hello", buff2[5];
15
16 memcpy(buff2, buff1, 5);
17 if (buff1[2] != buff2[2])
18 return 2;
19 printf("Initial test OK\n");
20 fflush(0);
21 // CHECK: Initial test OK
22
23 memcpy(buff2, buff1, 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_{{.*}}memcpy
27 // CHECK-NEXT: test_function {{.*}}dll_intercept_memcpy.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_memcpy.cc
30 // CHECK: 'buff2' <== Memory access at offset {{.*}} overflows this variable
31 return 0;
32 }
33