[compiler-rt] r209439 - [ASan/Win] Add more tests for operator new[]

Timur Iskhodzhanov timurrrr at google.com
Thu May 22 06:28:27 PDT 2014


Author: timurrrr
Date: Thu May 22 08:28:27 2014
New Revision: 209439

URL: http://llvm.org/viewvc/llvm-project?rev=209439&view=rev
Log:
[ASan/Win] Add more tests for operator new[]

Added:
    compiler-rt/trunk/test/asan/TestCases/Windows/dll_operator_array_new_left_oob.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cc
Modified:
    compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_left_oob.cc

Added: compiler-rt/trunk/test/asan/TestCases/Windows/dll_operator_array_new_left_oob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_operator_array_new_left_oob.cc?rev=209439&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_operator_array_new_left_oob.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_operator_array_new_left_oob.cc Thu May 22 08:28:27 2014
@@ -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;
+}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cc?rev=209439&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cc Thu May 22 08:28:27 2014
@@ -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;
+}

Modified: compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_left_oob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_left_oob.cc?rev=209439&r1=209438&r2=209439&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_left_oob.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_left_oob.cc Thu May 22 08:28:27 2014
@@ -2,17 +2,16 @@
 // FIXME: 'cat' is needed due to PR19744.
 // RUN: not %run %t 2>&1 | cat | FileCheck %s
 
-#include <windows.h>
-
 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;
 }

Added: compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cc?rev=209439&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cc Thu May 22 08:28:27 2014
@@ -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;
+}





More information about the llvm-commits mailing list