Tell MSan that memory initialized by libz is valid

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180094 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Support/Compression.cpp b/lib/Support/Compression.cpp
index f22d3db..36afa8c 100644
--- a/lib/Support/Compression.cpp
+++ b/lib/Support/Compression.cpp
@@ -15,6 +15,7 @@
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Config/config.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MemoryBuffer.h"
 #if LLVM_ENABLE_ZLIB == 1 && HAVE_ZLIB_H
@@ -55,9 +56,12 @@
   Status Res = encodeZlibReturnValue(::compress2(
       (Bytef *)TmpBuffer.get(), &CompressedSize,
       (const Bytef *)InputBuffer.data(), InputBuffer.size(), CLevel));
-  if (Res == StatusOK)
+  if (Res == StatusOK) {
     CompressedBuffer.reset(MemoryBuffer::getMemBufferCopy(
         StringRef(TmpBuffer.get(), CompressedSize)));
+    // Tell MSan that memory initialized by zlib is valid.
+    __msan_unpoison(CompressedBuffer.data(), CompressedBuffer.size());
+  }
   return Res;
 }
 
@@ -68,9 +72,12 @@
   Status Res = encodeZlibReturnValue(
       ::uncompress((Bytef *)TmpBuffer.get(), (uLongf *)&UncompressedSize,
                    (const Bytef *)InputBuffer.data(), InputBuffer.size()));
-  if (Res == StatusOK)
+  if (Res == StatusOK) {
     UncompressedBuffer.reset(MemoryBuffer::getMemBufferCopy(
         StringRef(TmpBuffer.get(), UncompressedSize)));
+    // Tell MSan that memory initialized by zlib is valid.
+    __msan_unpoison(UncompressedBuffer.data(), UncompressedBuffer.size());
+  }
   return Res;
 }