From ac1ad1d7d9f8dae6309f4f8082f5131703639dc9 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Mon, 6 Apr 2015 20:01:49 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234202 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/ScratchBuffer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Lex/ScratchBuffer.cpp b/lib/Lex/ScratchBuffer.cpp index 42cfca73d3..cd8a27e76c 100644 --- a/lib/Lex/ScratchBuffer.cpp +++ b/lib/Lex/ScratchBuffer.cpp @@ -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 OwnBuf = - llvm::MemoryBuffer::getNewUninitMemBuffer(RequestLen, ""); + llvm::MemoryBuffer::getNewMemBuffer(RequestLen, ""); llvm::MemoryBuffer &Buf = *OwnBuf; FileID FID = SourceMgr.createFileID(std::move(OwnBuf)); BufferStartLoc = SourceMgr.getLocForStartOfFile(FID); CurBuffer = const_cast(Buf.getBufferStart()); - BytesUsed = 1; - CurBuffer[0] = '0'; // Start out with a \0 for cleanliness. + BytesUsed = 0; } -- 2.50.1