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
5struct C {
6  int x;
7  ~C() {}
8};
9
10extern "C" __declspec(dllexport)
11int test_function() {
12  C *buffer = new C[42];
13  buffer[-2].x = 42;
14// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
15// CHECK: WRITE of size 4 at [[ADDR]] thread T0
16// CHECK-NEXT: test_function {{.*}}dll_operator_array_new_with_dtor_left_oob.cc:[[@LINE-3]]
17// CHECK-NEXT: main {{.*}}dll_host.cc
18//
19// FIXME: Currently it says "4 bytes ... left of 172-byte region",
20//        should be "8 bytes ... left of 168-byte region", see
21//        https://code.google.com/p/address-sanitizer/issues/detail?id=314
22// CHECK: [[ADDR]] is located {{.*}} bytes to the left of 172-byte region
23// FIXME: should get rid of the malloc/free frames called from the inside of
24// operator new/delete in DLLs.  Also, the operator new frame should have [].
25// CHECK-LABEL: allocated by thread T0 here:
26// CHECK-NEXT:   malloc
27// CHECK-NEXT:   operator new
28// CHECK-NEXT:   test_function {{.*}}dll_operator_array_new_with_dtor_left_oob.cc:[[@LINE-16]]
29// CHECK-NEXT:   main {{.*}}dll_host.cc
30// CHECK-LABEL: SUMMARY
31  delete [] buffer;
32  return 0;
33}
34