From b5e3d131f9ed6687cacffb67de8f54214dd8d2b3 Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Mon, 3 Apr 2023 22:50:14 +0800 Subject: [PATCH] [asan][test][win] Port more tests to not use clang-cl on MinGW Depends on D147432 Differential Revision: https://reviews.llvm.org/D147444 --- .../asan/TestCases/Windows/crt_initializers.cpp | 4 +--- .../asan/TestCases/Windows/demangled_names.cpp | 18 +++++++-------- .../TestCases/Windows/double_operator_delete.cpp | 27 +++++++++------------- .../Windows/operator_array_new_left_oob.cpp | 21 ++++++++--------- .../Windows/operator_array_new_right_oob.cpp | 19 +++++++-------- .../TestCases/Windows/operator_array_new_uaf.cpp | 26 +++++++++------------ .../operator_array_new_with_dtor_left_oob.cpp | 27 ++++++++++------------ .../asan/TestCases/Windows/sse_misalignment.cpp | 9 ++++---- 8 files changed, 66 insertions(+), 85 deletions(-) diff --git a/compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp b/compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp index a37d47a..5a1eee3 100644 --- a/compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp +++ b/compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp @@ -1,6 +1,4 @@ -// UNSUPPORTED: target={{.*-windows-gnu}} - -// RUN: %clang_cl_asan -Od %s -Fe%t +// RUN: %clang_cl_asan %Od %s %Fe%t // RUN: %run %t | FileCheck %s // This is a test for http://code.google.com/p/address-sanitizer/issues/detail?id=305 diff --git a/compiler-rt/test/asan/TestCases/Windows/demangled_names.cpp b/compiler-rt/test/asan/TestCases/Windows/demangled_names.cpp index d457d4d..cc1f146 100644 --- a/compiler-rt/test/asan/TestCases/Windows/demangled_names.cpp +++ b/compiler-rt/test/asan/TestCases/Windows/demangled_names.cpp @@ -1,7 +1,5 @@ -// UNSUPPORTED: target={{.*-windows-gnu}} - -// RUN: %clang_cl_asan -Od %s -Fe%t -// RUN: not %run %t 2>&1 | FileCheck %s +// RUN: %clang_cl_asan %Od %s %Fe%t +// RUN: not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,%if clang-cl %{MSVC%} %else %{MINGW%} // // This test makes sure ASan symbolizes stack traces the way they are typically // symbolized on Windows. @@ -44,9 +42,11 @@ int main() { char *buffer = (char*)malloc(42); free(buffer); A a(buffer); -// CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]] -// CHECK: foo::bar<42>{{.*}}demangled_names.cpp -// CHECK: foo::spam{{.*}}demangled_names.cpp -// CHECK: baz{{.*}}demangled_names.cpp -// CHECK: A::~A{{.*}}demangled_names.cpp + // CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]] + // CHECK: foo::bar<42>{{.*}}demangled_names.cpp + // CHECK: foo::spam{{.*}}demangled_names.cpp + // MSVC: baz{{.*}}demangled_names.cpp + // MINGW: baz{{.*}}demangled_names.cpp + // MSVC: A::~A{{.*}}demangled_names.cpp + // MINGW: A::~A(){{.*}}demangled_names.cpp } diff --git a/compiler-rt/test/asan/TestCases/Windows/double_operator_delete.cpp b/compiler-rt/test/asan/TestCases/Windows/double_operator_delete.cpp index 55304e2..3668a40 100644 --- a/compiler-rt/test/asan/TestCases/Windows/double_operator_delete.cpp +++ b/compiler-rt/test/asan/TestCases/Windows/double_operator_delete.cpp @@ -1,6 +1,4 @@ -// UNSUPPORTED: target={{.*-windows-gnu}} - -// RUN: %clang_cl_asan -Od %s -Fe%t +// RUN: %clang_cl_asan %Od %s %Fe%t // RUN: not %run %t 2>&1 | FileCheck %s #include @@ -9,19 +7,16 @@ int main() { int *x = new int[42]; delete [] x; delete [] x; -// CHECK: AddressSanitizer: attempting double-free on [[ADDR:0x[0-9a-f]+]] -// FIXME: The 'operator delete' frame should have []. -// CHECK-NEXT: {{#0 .* operator delete}} -// CHECK-NEXT: {{#1 .* main .*double_operator_delete.cpp}}:[[@LINE-4]] -// CHECK: [[ADDR]] is located 0 bytes inside of 168-byte region -// CHECK-LABEL: freed by thread T0 here: -// FIXME: The 'operator delete' frame should have []. -// CHECK-NEXT: {{#0 .* operator delete}} -// CHECK-NEXT: {{#1 .* main .*double_operator_delete.cpp}}:[[@LINE-10]] -// CHECK-LABEL: previously allocated by thread T0 here: -// FIXME: The 'operator new' frame should have []. -// CHECK-NEXT: {{#0 .* operator new}} -// CHECK-NEXT: {{#1 .* main .*double_operator_delete.cpp}}:[[@LINE-15]] + // CHECK: AddressSanitizer: attempting double-free on [[ADDR:0x[0-9a-f]+]] + // CHECK-NEXT: {{#0 .* operator delete}}[] + // CHECK-NEXT: {{#1 .* main .*double_operator_delete.cpp}}:[[@LINE-3]] + // CHECK: [[ADDR]] is located 0 bytes inside of 168-byte region + // CHECK-LABEL: freed by thread T0 here: + // CHECK-NEXT: {{#0 .* operator delete}}[] + // CHECK-NEXT: {{#1 .* main .*double_operator_delete.cpp}}:[[@LINE-8]] + // CHECK-LABEL: previously allocated by thread T0 here: + // CHECK-NEXT: {{#0 .* operator new}}[] + // CHECK-NEXT: {{#1 .* main .*double_operator_delete.cpp}}:[[@LINE-12]] return 0; } diff --git a/compiler-rt/test/asan/TestCases/Windows/operator_array_new_left_oob.cpp b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_left_oob.cpp index f8ffc69..96b9378 100644 --- a/compiler-rt/test/asan/TestCases/Windows/operator_array_new_left_oob.cpp +++ b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_left_oob.cpp @@ -1,19 +1,16 @@ -// UNSUPPORTED: target={{.*-windows-gnu}} - -// RUN: %clang_cl_asan -Od %s -Fe%t +// RUN: %clang_cl_asan %Od %s %Fe%t // RUN: not %run %t 2>&1 | FileCheck %s 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-NEXT: {{#0 .* main .*operator_array_new_left_oob.cpp}}:[[@LINE-3]] -// -// CHECK: [[ADDR]] is located 1 bytes before 42-byte region -// CHECK-LABEL: allocated by thread T0 here: -// FIXME: The 'operator new' frame should have []. -// CHECK-NEXT: {{#0 .* operator new}} -// CHECK-NEXT: {{#1 .* main .*operator_array_new_left_oob.cpp}}:[[@LINE-10]] + // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] + // CHECK: WRITE of size 1 at [[ADDR]] thread T0 + // CHECK-NEXT: {{#0 .* main .*operator_array_new_left_oob.cpp}}:[[@LINE-3]] + // + // CHECK: [[ADDR]] is located 1 bytes before 42-byte region + // CHECK-LABEL: allocated by thread T0 here: + // CHECK-NEXT: {{#0 .* operator new}}[] + // CHECK-NEXT: {{#1 .* main .*operator_array_new_left_oob.cpp}}:[[@LINE-9]] delete [] buffer; } diff --git a/compiler-rt/test/asan/TestCases/Windows/operator_array_new_right_oob.cpp b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_right_oob.cpp index b84e657..1e29d75 100644 --- a/compiler-rt/test/asan/TestCases/Windows/operator_array_new_right_oob.cpp +++ b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_right_oob.cpp @@ -1,6 +1,4 @@ -// UNSUPPORTED: target={{.*-windows-gnu}} - -// RUN: %clang_cl_asan -Od %s -Fe%t +// RUN: %clang_cl_asan %Od %s %Fe%t // RUN: not %run %t 2>&1 | FileCheck %s #include @@ -8,13 +6,12 @@ int main() { char *buffer = new char[42]; buffer[42] = 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_right_oob.cpp}}:[[@LINE-3]] -// CHECK: [[ADDR]] is located 0 bytes after 42-byte region -// CHECK: allocated by thread T0 here: -// FIXME: The 'operator new' frame should have []. -// CHECK: {{#0 .* operator new}} -// CHECK: {{#1 .* main .*operator_array_new_right_oob.cpp}}:[[@LINE-9]] + // 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_right_oob.cpp}}:[[@LINE-3]] + // CHECK: [[ADDR]] is located 0 bytes after 42-byte region + // CHECK: allocated by thread T0 here: + // CHECK: {{#0 .* operator new}}[] + // CHECK: {{#1 .* main .*operator_array_new_right_oob.cpp}}:[[@LINE-8]] delete [] buffer; } diff --git a/compiler-rt/test/asan/TestCases/Windows/operator_array_new_uaf.cpp b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_uaf.cpp index 367162e..edeee99 100644 --- a/compiler-rt/test/asan/TestCases/Windows/operator_array_new_uaf.cpp +++ b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_uaf.cpp @@ -1,6 +1,4 @@ -// UNSUPPORTED: target={{.*-windows-gnu}} - -// RUN: %clang_cl_asan -Od %s -Fe%t +// RUN: %clang_cl_asan %Od %s %Fe%t // RUN: not %run %t 2>&1 | FileCheck %s #include @@ -9,18 +7,16 @@ int main() { char *buffer = new char[42]; delete [] buffer; buffer[0] = 42; -// CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]] -// CHECK: WRITE of size 1 at [[ADDR]] thread T0 -// CHECK: {{#0 .* main .*operator_array_new_uaf.cpp}}:[[@LINE-3]] -// CHECK: [[ADDR]] is located 0 bytes inside of 42-byte region -// CHECK-LABEL: freed by thread T0 here: -// FIXME: The 'operator delete' frame should have []. -// CHECK: {{#0 .* operator delete}} -// CHECK: {{#1 .* main .*operator_array_new_uaf.cpp}}:[[@LINE-9]] -// CHECK-LABEL: previously allocated by thread T0 here: -// FIXME: The 'operator new' frame should have []. -// CHECK: {{#0 .* operator new}} -// CHECK: {{#1 .* main .*operator_array_new_uaf.cpp}}:[[@LINE-14]] + // CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]] + // CHECK: WRITE of size 1 at [[ADDR]] thread T0 + // CHECK: {{#0 .* main .*operator_array_new_uaf.cpp}}:[[@LINE-3]] + // CHECK: [[ADDR]] is located 0 bytes inside of 42-byte region + // CHECK-LABEL: freed by thread T0 here: + // CHECK: {{#0 .* operator delete}}[] + // CHECK: {{#1 .* main .*operator_array_new_uaf.cpp}}:[[@LINE-8]] + // CHECK-LABEL: previously allocated by thread T0 here: + // CHECK: {{#0 .* operator new}}[] + // CHECK: {{#1 .* main .*operator_array_new_uaf.cpp}}:[[@LINE-12]] return 0; } diff --git a/compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cpp b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cpp index 30fc1c7..cad28ae 100644 --- a/compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cpp +++ b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cpp @@ -1,6 +1,4 @@ -// UNSUPPORTED: target={{.*-windows-gnu}} - -// RUN: %clang_cl_asan -Od %s -Fe%t +// RUN: %clang_cl_asan %Od %s %Fe%t // RUN: not %run %t 2>&1 | FileCheck %s struct C { @@ -13,17 +11,16 @@ int __attribute__((noinline, optnone)) hide(int x) { return x; } int main() { C *buffer = new C[42]; buffer[hide(-(1 + (int)sizeof(void*) / 4))].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.cpp}}:[[@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 before {{(172|176)}}-byte region -// CHECK-LABEL: allocated by thread T0 here: -// FIXME: The 'operator new' frame should have []. -// CHECK-NEXT: {{#0 .* operator new}} -// CHECK-NEXT: {{#1 .* main .*operator_array_new_with_dtor_left_oob.cpp}}:[[@LINE-13]] + // 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.cpp}}:[[@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 before {{(172|176)}}-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.cpp}}:[[@LINE-12]] delete [] buffer; } diff --git a/compiler-rt/test/asan/TestCases/Windows/sse_misalignment.cpp b/compiler-rt/test/asan/TestCases/Windows/sse_misalignment.cpp index ce9bd63..1424ee8 100644 --- a/compiler-rt/test/asan/TestCases/Windows/sse_misalignment.cpp +++ b/compiler-rt/test/asan/TestCases/Windows/sse_misalignment.cpp @@ -1,8 +1,9 @@ -// UNSUPPORTED: target={{.*-windows-gnu}} - -// RUN: %clang_cl_asan -Od %s -Fe%t +// RUN: %clang_cl_asan %Od %s %Fe%t // RUN: %env_asan_opts=handle_sigfpe=1 not %run %t 2>&1 | FileCheck %s +// FIXME: On MinGW frame #0 does not include the line number? +// XFAIL: target={{.*-windows-gnu}} + // Test the error output from misaligned SSE2 memory access. This is a READ // memory access. Windows appears to always provide an address of -1 for these // types of faults, and there doesn't seem to be a way to distinguish them from @@ -27,4 +28,4 @@ int main() { // CHECK: before alignment fault // CHECK: ERROR: AddressSanitizer: access-violation on unknown address {{0x[fF]*}} // CHECK-NEXT: The signal is caused by a READ memory access. -// CHECK-NEXT: #0 {{.*}} in test(void) {{.*}}misalignment.cpp:{{.*}} +// CHECK-NEXT: #0 {{.*}} in test({{(void)?}}) {{.*}}misalignment.cpp:{{.*}} -- 2.7.4