[compiler-rt] [msan] Detect dereferencing zero-alloc as use-of-uninitialized-value (PR #155944)
    Vitaly Buka via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Fri Aug 29 23:59:02 PDT 2025
    
    
  
================
@@ -230,6 +230,12 @@ static void *MsanAllocate(BufferedStackTrace *stack, uptr size, uptr alignment,
       __msan_set_origin(allocated, size, o.raw_id());
     }
   }
+
+  uptr actually_allocated_size = allocator.GetActuallyAllocatedSize(allocated);
----------------
vitalybuka wrote:
> > Why did you create this patch than, it falls into the same category?
> 
> Zero-sized allocations are a special case. POSIX allows that malloc(0) could even return NULL, which definitely should not be dereferenced. The new behavior (returning a non-NULL pointer, but not allowing it to be dereferenced) is a compromise between compatibility and detection.
> It is expensive from a cost-benefit perspective. It has some cost, but the benefit is limited (detecting issues that are out of scope for MSan).
a. my intuition is it's almost zero cost, you would not be able to measure
b. this patch is already "out of scope"
https://github.com/llvm/llvm-project/pull/155944
    
    
More information about the llvm-commits
mailing list