<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 6, 2015 at 1:01 PM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@googlemail.com" target="_blank">benny.kra@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: d0k<br>
Date: Mon Apr  6 15:01:49 2015<br>
New Revision: 234202<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=234202&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=234202&view=rev</a><br>
Log:<br>
MSan told me that we actually dump the entire scratch buffer into PCH files, initialize it.<br>
<br>
Writing 4k of zeros is preferrable to 4k of random memory. Document that. While<br>
there remove the initialization of the first byte of the buffer and start at<br>
index zero. It was writing a literal '0' instead of a null byte at the<br>
beginning anyways, which didn't matter since we never read it.<br></blockquote><div><br>Wonder if we could just get smarter about writing it out - only writing the needed bytes (ones that have been initialized) - should be relatively easy, unless we leave holes in it? (& if we need the rest of the zeros, either just resizing the file, or writing zeros right to the file without writing them to this buffer first might be do-able)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
    cfe/trunk/lib/Lex/ScratchBuffer.cpp<br>
<br>
Modified: cfe/trunk/lib/Lex/ScratchBuffer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ScratchBuffer.cpp?rev=234202&r1=234201&r2=234202&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ScratchBuffer.cpp?rev=234202&r1=234201&r2=234202&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Lex/ScratchBuffer.cpp (original)<br>
+++ cfe/trunk/lib/Lex/ScratchBuffer.cpp Mon Apr  6 15:01:49 2015<br>
@@ -64,12 +64,13 @@ void ScratchBuffer::AllocScratchBuffer(u<br>
   if (RequestLen < ScratchBufSize)<br>
     RequestLen = ScratchBufSize;<br>
<br>
+  // Get scratch buffer. Zero-initialize it so it can be dumped into a PCH file<br>
+  // deterministically.<br>
   std::unique_ptr<llvm::MemoryBuffer> OwnBuf =<br>
-      llvm::MemoryBuffer::getNewUninitMemBuffer(RequestLen, "<scratch space>");<br>
+      llvm::MemoryBuffer::getNewMemBuffer(RequestLen, "<scratch space>");<br>
   llvm::MemoryBuffer &Buf = *OwnBuf;<br>
   FileID FID = SourceMgr.createFileID(std::move(OwnBuf));<br>
   BufferStartLoc = SourceMgr.getLocForStartOfFile(FID);<br>
   CurBuffer = const_cast<char*>(Buf.getBufferStart());<br>
-  BytesUsed = 1;<br>
-  CurBuffer[0] = '0';  // Start out with a \0 for cleanliness.<br>
+  BytesUsed = 0;<br>
 }<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>