[ASan/Win] Hide index from compiler to avoid new clang warning

This commit is contained in:
Reid Kleckner 2021-06-11 16:12:07 -07:00
parent 37a2c4517b
commit b9af157fd1
2 changed files with 6 additions and 2 deletions

View File

@ -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]]

View File

@ -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]]