r234202 - MSan told me that we actually dump the entire scratch buffer into PCH files, initialize it.

David Blaikie dblaikie at gmail.com
Mon Apr 6 13:19:28 PDT 2015


On Mon, Apr 6, 2015 at 1:15 PM, Benjamin Kramer <benny.kra at gmail.com> wrote:

> On Mon, Apr 6, 2015 at 10:09 PM, David Blaikie <dblaikie at gmail.com> wrote:
> >
> >
> > On Mon, Apr 6, 2015 at 1:01 PM, Benjamin Kramer <
> benny.kra at googlemail.com>
> > 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)
>
> I was wondering the same but this buffer looks in no way special to
> the AST writer (except the name) and we don't know where it ends
> without scanning the buffer. Implementing a general zero tail
> compression scheme doesn't feel like it's worth it.
>

Hrm. Rightio.

- Dave


>
> - Ben
>
> >
> >>
> >>
> >> 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
> >> cfe-commits at cs.uiuc.edu
> >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150406/f337603f/attachment.html>


More information about the cfe-commits mailing list