r322268 - [Lex] Use WritableMemoryBuffer in ScratchBuffer.cpp

Pavel Labath via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 11 02:43:45 PST 2018


Author: labath
Date: Thu Jan 11 02:43:45 2018
New Revision: 322268

URL: http://llvm.org/viewvc/llvm-project?rev=322268&view=rev
Log:
[Lex] Use WritableMemoryBuffer in ScratchBuffer.cpp

This avoids the need to const_cast the buffer contents to write to it.

NFCI.

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=322268&r1=322267&r2=322268&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ScratchBuffer.cpp (original)
+++ cfe/trunk/lib/Lex/ScratchBuffer.cpp Thu Jan 11 02:43:45 2018
@@ -74,11 +74,11 @@ void ScratchBuffer::AllocScratchBuffer(u
 
   // Get scratch buffer. Zero-initialize it so it can be dumped into a PCH file
   // deterministically.
-  std::unique_ptr<llvm::MemoryBuffer> OwnBuf =
-      llvm::MemoryBuffer::getNewMemBuffer(RequestLen, "<scratch space>");
-  llvm::MemoryBuffer &Buf = *OwnBuf;
+  std::unique_ptr<llvm::WritableMemoryBuffer> OwnBuf =
+      llvm::WritableMemoryBuffer::getNewMemBuffer(RequestLen,
+                                                  "<scratch space>");
+  CurBuffer = OwnBuf->getBufferStart();
   FileID FID = SourceMgr.createFileID(std::move(OwnBuf));
   BufferStartLoc = SourceMgr.getLocForStartOfFile(FID);
-  CurBuffer = const_cast<char*>(Buf.getBufferStart());
   BytesUsed = 0;
 }




More information about the cfe-commits mailing list