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 <malloc.h>
6
7extern "C" __declspec(dllexport)
8int test_function() {
9  int *buffer = (int*)malloc(42);
10  free(buffer);
11  buffer[0] = 42;
12// CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
13// CHECK: WRITE of size 4 at [[ADDR]] thread T0
14// CHECK-NEXT:  test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-3]]
15// CHECK-NEXT:  main {{.*}}dll_host
16//
17// CHECK: [[ADDR]] is located 0 bytes inside of 42-byte region
18// CHECK-LABEL: freed by thread T0 here:
19// CHECK-NEXT:  free
20// CHECK-NEXT:  test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-10]]
21// CHECK-NEXT:  main {{.*}}dll_host
22//
23// CHECK-LABEL: previously allocated by thread T0 here:
24// CHECK-NEXT:  malloc
25// CHECK-NEXT:  test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-16]]
26// CHECK-NEXT:  main {{.*}}dll_host
27  return 0;
28}
29