HomePhabricator

[lsan][test] Add malloc(0) and realloc(p, 0) tests

Authored by MaskRay on Mon, Mar 29, 11:41 AM.

Description

[lsan][test] Add malloc(0) and realloc(p, 0) tests

Details

Committed
MaskRayMon, Mar 29, 11:41 AM
Parents
rG9b0517035fae: [mlir] Enhance InferShapedTypeOpInterface and move LinalgOps to use them.
Branches
Unknown
Tags
Unknown

Event Timeline

@MaskRay malloc_zero.c has been failing on our AArch32 bot: http://lab.llvm.org:8011/#/builders/59/builds/1596

******************** TEST 'LeakSanitizer-Standalone-armhf :: TestCases/malloc_zero.c' FAILED ********************
Script:
--
: 'RUN: at line 1';      /home/tcwg-buildslave/worker/clang-cmake-armv7-full/stage2/./bin/clang  -O0  -mcpu=cortex-a15 -mfpu=vfpv3 -marm   -gline-tables-only -fsanitize=leak -I/home/tcwg-buildslave/worker/clang-cmake-armv7-full/llvm/compiler-rt/test/lsan/../ /home/tcwg-buildslave/worker/clang-cmake-armv7-full/llvm/compiler-rt/test/lsan/TestCases/malloc_zero.c -o /home/tcwg-buildslave/worker/clang-cmake-armv7-full/stage2/projects/compiler-rt/test/lsan/ARMHFLsanConfig/TestCases/Output/malloc_zero.c.tmp
: 'RUN: at line 2';   env LSAN_OPTIONS=:detect_leaks=1:use_stacks=0 not  /home/tcwg-buildslave/worker/clang-cmake-armv7-full/stage2/projects/compiler-rt/test/lsan/ARMHFLsanConfig/TestCases/Output/malloc_zero.c.tmp 2>&1 | FileCheck /home/tcwg-buildslave/worker/clang-cmake-armv7-full/llvm/compiler-rt/test/lsan/TestCases/malloc_zero.c
--
Exit Code: 1
Command Output (stderr):
--
/home/tcwg-buildslave/worker/clang-cmake-armv7-full/llvm/compiler-rt/test/lsan/TestCases/malloc_zero.c:7:11: error: CHECK: expected string not found in input
// CHECK: {{Leak|Address}}Sanitizer: detected memory leaks
          ^
<stdin>:1:1: note: scanning from here
zero: 0x408003d0
^
Input file: <stdin>
Check file: /home/tcwg-buildslave/worker/clang-cmake-armv7-full/llvm/compiler-rt/test/lsan/TestCases/malloc_zero.c
-dump-input=help explains the following input dump.
Input was:
<<<<<<
         1: zero: 0x408003d0 
check:7     X~~~~~~~~~~~~~~~~ error: no match found
>>>>>>
--
********************

I assume this means the C library isn't doing any allocation at all for malloc(0) and therefore there's no leak for the sanitizer to find? Or does the sanitizer assume that any malloc will be at least 1 byte?

https://pubs.opengroup.org/onlinepubs/009695399/functions/malloc.html

If size is 0, either a null pointer or a unique pointer that can be successfully passed to free() shall be returned.

So it would be valid to return a pointer to a zero length allocation that your free knows is empty, but I'm just guessing for the moment.

Marked the test UNSUPPORTED for now while we figure this out: https://reviews.llvm.org/rG466fab5c9410abb79f1a70c5075147e9a768124e

MaskRay added a comment.EditedThu, Apr 8, 9:26 AM

Marked the test UNSUPPORTED for now while we figure this out: https://reviews.llvm.org/rG466fab5c9410abb79f1a70c5075147e9a768124e

Thanks!

The behavior of malloc(0) is implementation-defined. It is still confusing that glibc arm behaves differently from other ports. It could also be that p = 0; is not sufficient to cause a leak. 32-bit architectures generally have worse lsan support.