diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp --- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp +++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp @@ -162,6 +162,9 @@ static void *HwasanAllocate(StackTrace *stack, uptr orig_size, uptr alignment, bool zeroise) { + // Keep this consistent with LSAN and ASAN behavior. + if (orig_size == 0) + orig_size = 1; if (orig_size > kMaxAllowedMallocSize) { if (AllocatorMayReturnNull()) { Report("WARNING: HWAddressSanitizer failed to allocate 0x%zx bytes\n", diff --git a/compiler-rt/test/lsan/TestCases/malloc_zero.c b/compiler-rt/test/lsan/TestCases/malloc_zero.c --- a/compiler-rt/test/lsan/TestCases/malloc_zero.c +++ b/compiler-rt/test/lsan/TestCases/malloc_zero.c @@ -1,9 +1,6 @@ // RUN: %clang_lsan %s -o %t // RUN: %env_lsan_opts=use_stacks=0 not %run %t 2>&1 | FileCheck %s -// Fixme: remove once test passes with hwasan -// UNSUPPORTED: hwasan - /// Fails when only leak sanitizer is enabled // UNSUPPORTED: arm-linux, armhf-linux @@ -11,7 +8,7 @@ #include // CHECK: {{Leak|Address}}Sanitizer: detected memory leaks -// CHECK: {{Leak|Address}}Sanitizer: 1 byte(s) leaked in 1 allocation(s). +// CHECK: {{Leak|Address}}Sanitizer: {{0|1}} byte(s) leaked in 1 allocation(s). int main() { // The behavior of malloc(0) is implementation-defined.