1// RUN: %clang_cl_asan %Od %s %Fe%t
2// RUN: not %run %t 2>&1 | FileCheck %s
3
4struct C {
5 int x;
6 ~C() {}
7};
8
9int __attribute__((noinline, optnone)) hide(int x) { return x; }
10
11int main() {
12 C *buffer = new C[42];
13 buffer[hide(x: -(1 + (int)sizeof(void*) / 4))].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: {{#0 .* main .*operator_array_new_with_dtor_left_oob.cpp}}:[[@LINE-3]]
17 //
18 // FIXME: Currently it says "4 bytes ... left of 172-byte region",
19 // should be "8 bytes ... left of 168-byte region", see
20 // https://code.google.com/p/address-sanitizer/issues/detail?id=314
21 // CHECK: [[ADDR]] is located {{.*}} bytes before {{(172|176)}}-byte region
22 // CHECK-LABEL: allocated by thread T0 here:
23 // CHECK-NEXT: {{#0 .* operator new}}[]
24 // CHECK-NEXT: {{#1 .* main .*operator_array_new_with_dtor_left_oob.cpp}}:[[@LINE-12]]
25 delete [] buffer;
26}
27

source code of compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cpp