From 040725723ed28a8188ca8d0a7301fb2b76fbb79c Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Mon, 6 Apr 2015 20:01:49 +0000 Subject: 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 --- clang/lib/Lex/ScratchBuffer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'clang/lib/Lex/ScratchBuffer.cpp') diff --git a/clang/lib/Lex/ScratchBuffer.cpp b/clang/lib/Lex/ScratchBuffer.cpp index 42cfca73d3d..cd8a27e76c2 100644 --- a/clang/lib/Lex/ScratchBuffer.cpp +++ b/clang/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; } -- cgit v1.2.3