forked from OSchip/llvm-project
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. llvm-svn: 234202
This commit is contained in:
parent
a5099dce62
commit
040725723e
|
@ -64,12 +64,13 @@ void ScratchBuffer::AllocScratchBuffer(unsigned RequestLen) {
|
|||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue