From: Timur Iskhodzhanov Date: Thu, 22 May 2014 13:28:27 +0000 (+0000) Subject: [ASan/Win] Add more tests for operator new[] X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=498e56adb6c05d69afc300eeadce12fadfc3e477;p=platform%2Fupstream%2Fllvm.git [ASan/Win] Add more tests for operator new[] llvm-svn: 209439 --- diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_left_oob.cc b/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_left_oob.cc new file mode 100644 index 0000000..0c98322 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_left_oob.cc @@ -0,0 +1,26 @@ +// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t +// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll +// FIXME: 'cat' is needed due to PR19744. +// RUN: not %run %t %t.dll 2>&1 | cat | FileCheck %s + +extern "C" __declspec(dllexport) +int test_function() { + char *buffer = new char[42]; + buffer[-1] = 42; +// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] +// CHECK: WRITE of size 1 at [[ADDR]] thread T0 +// CHECK-NEXT: test_function {{.*}}dll_operator_array_new_left_oob.cc:[[@LINE-3]] +// CHECK-NEXT: main {{.*}}dll_host.cc +// +// CHECK: [[ADDR]] is located 1 bytes to the left of 42-byte region +// CHECK-LABEL: allocated by thread T0 here: +// FIXME: should get rid of the malloc/free frames called from the inside of +// operator new/delete in DLLs. Also, the operator new frame should have []. +// CHECK-NEXT: malloc +// CHECK-NEXT: operator new +// CHECK-NEXT: test_function {{.*}}dll_operator_array_new_left_oob.cc:[[@LINE-13]] +// CHECK-NEXT: main {{.*}}dll_host.cc +// CHECK-LABEL: SUMMARY + delete [] buffer; + return 0; +} diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cc b/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cc new file mode 100644 index 0000000..c014b4b --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cc @@ -0,0 +1,34 @@ +// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t +// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll +// FIXME: 'cat' is needed due to PR19744. +// RUN: not %run %t %t.dll 2>&1 | cat | FileCheck %s + +struct C { + int x; + ~C() {} +}; + +extern "C" __declspec(dllexport) +int test_function() { + C *buffer = new C[42]; + buffer[-2].x = 42; +// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] +// CHECK: WRITE of size 4 at [[ADDR]] thread T0 +// CHECK-NEXT: test_function {{.*}}dll_operator_array_new_with_dtor_left_oob.cc:[[@LINE-3]] +// CHECK-NEXT: main {{.*}}dll_host.cc +// +// FIXME: Currently it says "4 bytes ... left of 172-byte region", +// should be "8 bytes ... left of 168-byte region", see +// https://code.google.com/p/address-sanitizer/issues/detail?id=314 +// CHECK: [[ADDR]] is located {{.*}} bytes to the left of 172-byte region +// FIXME: should get rid of the malloc/free frames called from the inside of +// operator new/delete in DLLs. Also, the operator new frame should have []. +// CHECK-LABEL: allocated by thread T0 here: +// CHECK-NEXT: malloc +// CHECK-NEXT: operator new +// CHECK-NEXT: test_function {{.*}}dll_operator_array_new_with_dtor_left_oob.cc:[[@LINE-16]] +// CHECK-NEXT: main {{.*}}dll_host.cc +// CHECK-LABEL: SUMMARY + delete [] buffer; + return 0; +} diff --git a/compiler-rt/test/asan/TestCases/Windows/operator_array_new_left_oob.cc b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_left_oob.cc index 3e5b96a..33b6377 100644 --- a/compiler-rt/test/asan/TestCases/Windows/operator_array_new_left_oob.cc +++ b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_left_oob.cc @@ -2,17 +2,16 @@ // FIXME: 'cat' is needed due to PR19744. // RUN: not %run %t 2>&1 | cat | FileCheck %s -#include - int main() { char *buffer = new char[42]; buffer[-1] = 42; // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] // CHECK: WRITE of size 1 at [[ADDR]] thread T0 -// CHECK: {{#0 .* main .*operator_array_new_left_oob.cc}}:[[@LINE-3]] +// CHECK-NEXT: {{#0 .* main .*operator_array_new_left_oob.cc}}:[[@LINE-3]] +// // CHECK: [[ADDR]] is located 1 bytes to the left of 42-byte region -// CHECK: allocated by thread T0 here: -// CHECK: {{#0 .* operator new}}[] -// CHECK: {{#1 .* main .*operator_array_new_left_oob.cc}}:[[@LINE-8]] +// CHECK-LABEL: allocated by thread T0 here: +// CHECK-NEXT: {{#0 .* operator new}}[] +// CHECK-NEXT: {{#1 .* main .*operator_array_new_left_oob.cc}}:[[@LINE-9]] delete [] buffer; } diff --git a/compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cc b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cc new file mode 100644 index 0000000..aa5f495 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cc @@ -0,0 +1,25 @@ +// RUN: %clangxx_asan -O0 %s -Fe%t +// FIXME: 'cat' is needed due to PR19744. +// RUN: not %run %t 2>&1 | cat | FileCheck %s + +struct C { + int x; + ~C() {} +}; + +int main() { + C *buffer = new C[42]; + buffer[-2].x = 42; +// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] +// CHECK: WRITE of size 4 at [[ADDR]] thread T0 +// CHECK-NEXT: {{#0 .* main .*operator_array_new_with_dtor_left_oob.cc}}:[[@LINE-3]] +// +// FIXME: Currently it says "4 bytes ... left of 172-byte region", +// should be "8 bytes ... left of 168-byte region", see +// https://code.google.com/p/address-sanitizer/issues/detail?id=314 +// CHECK: [[ADDR]] is located {{.*}} bytes to the left of 172-byte region +// CHECK-LABEL: allocated by thread T0 here: +// CHECK-NEXT: {{#0 .* operator new}}[] +// CHECK-NEXT: {{#1 .* main .*operator_array_new_with_dtor_left_oob.cc}}:[[@LINE-12]] + delete [] buffer; +}