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