r234202 - MSan told me that we actually dump the entire scratch buffer into PCH files, initialize it.

Benjamin Kramer benny.kra at googlemail.com
Mon Apr 6 13:01:49 PDT 2015


Author: d0k
Date: Mon Apr  6 15:01:49 2015
New Revision: 234202

URL: http://llvm.org/viewvc/llvm-project?rev=234202&view=rev
Log:
MSan told me that we actually dump the entire scratch buffer into PCH files, initialize it.

Writing 4k of zeros is preferrable to 4k of random memory. Document that. While
there remove the initialization of the first byte of the buffer and start at
index zero. It was writing a literal '0' instead of a null byte at the
beginning anyways, which didn't matter since we never read it.

Modified:
    cfe/trunk/lib/Lex/ScratchBuffer.cpp

Modified: cfe/trunk/lib/Lex/ScratchBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ScratchBuffer.cpp?rev=234202&r1=234201&r2=234202&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ScratchBuffer.cpp (original)
+++ cfe/trunk/lib/Lex/ScratchBuffer.cpp Mon Apr  6 15:01:49 2015
@@ -64,12 +64,13 @@ void ScratchBuffer::AllocScratchBuffer(u
   if (RequestLen < ScratchBufSize)
     RequestLen = ScratchBufSize;
 
+  // Get scratch buffer. Zero-initialize it so it can be dumped into a PCH file
+  // deterministically.
   std::unique_ptr<llvm::MemoryBuffer> OwnBuf =
-      llvm::MemoryBuffer::getNewUninitMemBuffer(RequestLen, "<scratch space>");
+      llvm::MemoryBuffer::getNewMemBuffer(RequestLen, "<scratch space>");
   llvm::MemoryBuffer &Buf = *OwnBuf;
   FileID FID = SourceMgr.createFileID(std::move(OwnBuf));
   BufferStartLoc = SourceMgr.getLocForStartOfFile(FID);
   CurBuffer = const_cast<char*>(Buf.getBufferStart());
-  BytesUsed = 1;
-  CurBuffer[0] = '0';  // Start out with a \0 for cleanliness.
+  BytesUsed = 0;
 }





More information about the cfe-commits mailing list