<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 6, 2015 at 1:15 PM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@gmail.com" target="_blank">benny.kra@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mon, Apr 6, 2015 at 10:09 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
><br>
><br>
> On Mon, Apr 6, 2015 at 1:01 PM, Benjamin Kramer <<a href="mailto:benny.kra@googlemail.com">benny.kra@googlemail.com</a>><br>
> wrote:<br>
>><br>
>> 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<br>
>> files, initialize it.<br>
>><br>
>> Writing 4k of zeros is preferrable to 4k of random memory. Document that.<br>
>> While<br>
>> there remove the initialization of the first byte of the buffer and start<br>
>> 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>
><br>
><br>
> Wonder if we could just get smarter about writing it out - only writing the<br>
> needed bytes (ones that have been initialized) - should be relatively easy,<br>
> unless we leave holes in it? (& if we need the rest of the zeros, either<br>
> just resizing the file, or writing zeros right to the file without writing<br>
> them to this buffer first might be do-able)<br>
<br>
</span>I was wondering the same but this buffer looks in no way special to<br>
the AST writer (except the name) and we don't know where it ends<br>
without scanning the buffer. Implementing a general zero tail<br>
compression scheme doesn't feel like it's worth it.<br></blockquote><div><br>Hrm. Rightio.<br><br>- Dave<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
- Ben<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
>><br>
>><br>
>> Modified:<br>
>>     cfe/trunk/lib/Lex/ScratchBuffer.cpp<br>
>><br>
>> Modified: cfe/trunk/lib/Lex/ScratchBuffer.cpp<br>
>> URL:<br>
>> <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>
>> ==============================================================================<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<br>
>> PCH file<br>
>> +  // deterministically.<br>
>>    std::unique_ptr<llvm::MemoryBuffer> OwnBuf =<br>
>> -      llvm::MemoryBuffer::getNewUninitMemBuffer(RequestLen, "<scratch<br>
>> 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>
><br>
><br>
</div></div></blockquote></div><br></div></div>