On Mon, Apr 6, 2015 at 1:01 PM, Benjamin Kramer <[email protected]> wrote:
> 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. > 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) > > 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; > } > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
