[PATCH] D41387: Remove llvm::MemoryBuffer const_casts
Pavel Labath via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 20 03:35:37 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL321167: Remove llvm::MemoryBuffer const_casts (authored by labath, committed by ).
Repository:
rL LLVM
https://reviews.llvm.org/D41387
Files:
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
Index: cfe/trunk/lib/Lex/Preprocessor.cpp
===================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp
+++ cfe/trunk/lib/Lex/Preprocessor.cpp
@@ -420,10 +420,9 @@
CodeCompletionFile = File;
CodeCompletionOffset = Position - Buffer->getBufferStart();
- std::unique_ptr<MemoryBuffer> NewBuffer =
- MemoryBuffer::getNewUninitMemBuffer(Buffer->getBufferSize() + 1,
- Buffer->getBufferIdentifier());
- char *NewBuf = const_cast<char*>(NewBuffer->getBufferStart());
+ auto NewBuffer = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(
+ Buffer->getBufferSize() + 1, Buffer->getBufferIdentifier());
+ char *NewBuf = NewBuffer->getBufferStart();
char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf);
*NewPos = '\0';
std::copy(Position, Buffer->getBufferEnd(), NewPos+1);
Index: cfe/trunk/lib/Basic/SourceManager.cpp
===================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp
+++ cfe/trunk/lib/Basic/SourceManager.cpp
@@ -125,11 +125,12 @@
// possible.
if (!BufferOrError) {
StringRef FillStr("<<<MISSING SOURCE FILE>>>\n");
- Buffer.setPointer(MemoryBuffer::getNewUninitMemBuffer(
- ContentsEntry->getSize(), "<invalid>").release());
- char *Ptr = const_cast<char*>(Buffer.getPointer()->getBufferStart());
+ auto BackupBuffer = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(
+ ContentsEntry->getSize(), "<invalid>");
+ char *Ptr = BackupBuffer->getBufferStart();
for (unsigned i = 0, e = ContentsEntry->getSize(); i != e; ++i)
Ptr[i] = FillStr[i % FillStr.size()];
+ Buffer.setPointer(BackupBuffer.release());
if (Diag.isDiagnosticInFlight())
Diag.SetDelayedDiagnostic(diag::err_cannot_open_file,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41387.127677.patch
Type: text/x-patch
Size: 1863 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171220/c9c84278/attachment.bin>
More information about the cfe-commits
mailing list