diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-11-25 15:24:07 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-11-25 15:24:07 +0000 |
commit | 28cacae2f1150bda344b9cedc182ee6f8a81683c (patch) | |
tree | afc44c3d11a8ae9a7e445b87a0a5affc44fc2031 /llvm/lib/Support/Compression.cpp | |
parent | 089c066bd65eb7b12f9d2e2d6382a91a6cedaea8 (diff) | |
download | bcm5719-llvm-28cacae2f1150bda344b9cedc182ee6f8a81683c.tar.gz bcm5719-llvm-28cacae2f1150bda344b9cedc182ee6f8a81683c.zip |
[msan] Annotate zlib functions for MemorySanitizer.
Mark destination buffer in zlib::compress and zlib::decompress as fully
initialized.
When building LLVM with system zlib and MemorySanitizer instrumentation,
MSan does not observe memory writes in zlib code and erroneously considers
zlib output buffers as uninitialized, resulting in false use-of-uninitialized
memory reports. This change helps MSan understand the state of that memory
and prevents such reports.
llvm-svn: 222763
Diffstat (limited to 'llvm/lib/Support/Compression.cpp')
-rw-r--r-- | llvm/lib/Support/Compression.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Support/Compression.cpp b/llvm/lib/Support/Compression.cpp index c32eb21343e..17ae2957d12 100644 --- a/llvm/lib/Support/Compression.cpp +++ b/llvm/lib/Support/Compression.cpp @@ -54,6 +54,9 @@ zlib::Status zlib::compress(StringRef InputBuffer, Status Res = encodeZlibReturnValue(::compress2( (Bytef *)CompressedBuffer.data(), &CompressedSize, (const Bytef *)InputBuffer.data(), InputBuffer.size(), CLevel)); + // Tell MemorySanitizer that zlib output buffer is fully initialized. + // This avoids a false report when running LLVM with uninstrumented ZLib. + __msan_unpoison(CompressedBuffer.data(), CompressedSize); CompressedBuffer.resize(CompressedSize); return Res; } @@ -65,6 +68,9 @@ zlib::Status zlib::uncompress(StringRef InputBuffer, Status Res = encodeZlibReturnValue(::uncompress( (Bytef *)UncompressedBuffer.data(), (uLongf *)&UncompressedSize, (const Bytef *)InputBuffer.data(), InputBuffer.size())); + // Tell MemorySanitizer that zlib output buffer is fully initialized. + // This avoids a false report when running LLVM with uninstrumented ZLib. + __msan_unpoison(UncompressedBuffer.data(), UncompressedSize); UncompressedBuffer.resize(UncompressedSize); return Res; } |