1 | // RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t |
2 | // RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll |
3 | // RUN: not %run %t %t.dll 2>&1 | FileCheck %s |
4 | |
5 | struct C { |
6 | int x; |
7 | ~C() {} |
8 | }; |
9 | |
10 | int __attribute__((noinline, optnone)) hide(int x) { return x; } |
11 | |
12 | extern "C" __declspec(dllexport) |
13 | int test_function() { |
14 | C *buffer = new C[42]; |
15 | buffer[hide(x: -(1 + (int)sizeof(void*) / 4))].x = 42; |
16 | // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] |
17 | // CHECK: WRITE of size 4 at [[ADDR]] thread T0 |
18 | // CHECK-NEXT: test_function {{.*}}dll_operator_array_new_with_dtor_left_oob.cpp:[[@LINE-3]] |
19 | // CHECK-NEXT: main {{.*}}dll_host.cpp |
20 | // |
21 | // FIXME: Currently it says "4 bytes ... left of 172-byte region", |
22 | // should be "8 bytes ... left of 168-byte region", see |
23 | // https://code.google.com/p/address-sanitizer/issues/detail?id=314 |
24 | // CHECK: [[ADDR]] is located {{.*}} bytes before {{(172|176)}}-byte region |
25 | // FIXME: Should get rid of the malloc/free frames called from the inside of |
26 | // operator new/delete in DLLs when using -MT CRT. |
27 | // FIXME: The operator new frame should have []. |
28 | // CHECK-LABEL: allocated by thread T0 here: |
29 | // CHECK: operator new |
30 | // CHECK-NEXT: test_function {{.*}}dll_operator_array_new_with_dtor_left_oob.cpp:[[@LINE-16]] |
31 | // CHECK-NEXT: main {{.*}}dll_host.cpp |
32 | // CHECK-LABEL: SUMMARY |
33 | delete [] buffer; |
34 | return 0; |
35 | } |
36 | |