[SystemZ] Optimize sign-extends of vector setccs
[oota-llvm.git] / lib / Support / Compression.cpp
index d0adf79ec7805e9e7b86c57a8e8816d7a1cbc723..fd8a8743ea180aca3a859cd37049610d9f3ffaeb 100644 (file)
@@ -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
@@ -23,7 +24,7 @@
 
 using namespace llvm;
 
-#if LLVM_ENABLE_ZLIB == 1
+#if LLVM_ENABLE_ZLIB == 1 && HAVE_LIBZ
 static int encodeZlibCompressionLevel(zlib::CompressionLevel Level) {
   switch (Level) {
     case zlib::NoCompression: return 0;
@@ -31,6 +32,7 @@ static int encodeZlibCompressionLevel(zlib::CompressionLevel Level) {
     case zlib::DefaultCompression: return Z_DEFAULT_COMPRESSION;
     case zlib::BestSizeCompression: return 9;
   }
+  llvm_unreachable("Invalid zlib::CompressionLevel!");
 }
 
 static zlib::Status encodeZlibReturnValue(int ReturnValue) {
@@ -54,9 +56,12 @@ zlib::Status zlib::compress(StringRef InputBuffer,
   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->getBufferStart(), CompressedSize);
+  }
   return Res;
 }
 
@@ -67,9 +72,12 @@ zlib::Status zlib::uncompress(StringRef InputBuffer,
   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->getBufferStart(), UncompressedSize);
+  }
   return Res;
 }