From b9af157fd18d375ac689ae241b831ccd95c42243 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 11 Jun 2021 16:12:07 -0700 Subject: [PATCH] [ASan/Win] Hide index from compiler to avoid new clang warning --- .../TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cpp | 4 +++- .../asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cpp b/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cpp index a08524f..e81057d 100644 --- a/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cpp +++ b/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cpp @@ -7,10 +7,12 @@ struct C { ~C() {} }; +int __attribute__((noinline, optnone)) hide(int x) { return x; } + extern "C" __declspec(dllexport) int test_function() { C *buffer = new C[42]; - buffer[-(1 + sizeof(void*) / 4)].x = 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: test_function {{.*}}dll_operator_array_new_with_dtor_left_oob.cpp:[[@LINE-3]] 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 0af00fb..97e85f4 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 @@ -6,9 +6,11 @@ struct C { ~C() {} }; +int __attribute__((noinline, optnone)) hide(int x) { return x; } + int main() { C *buffer = new C[42]; - buffer[-(1 + sizeof(void*) / 4)].x = 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]] -- 2.7.4