[llvm] r321257 - [Support] Remove MemoryBuffer::getNewUninitMemBuffer
Pavel Labath via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 21 03:27:21 PST 2017
Author: labath
Date: Thu Dec 21 03:27:21 2017
New Revision: 321257
URL: http://llvm.org/viewvc/llvm-project?rev=321257&view=rev
Log:
[Support] Remove MemoryBuffer::getNewUninitMemBuffer
There is nothing useful that can be done with a read-only uninitialized
buffer without const_casting its contents to initialize it. A better
solution is to obtain a writable buffer
(WritableMemoryBuffer::getNewUninitMemBuffer), and then convert it to a
read-only buffer after initialization. All callers of this function have
already been updated to do this, so this function is now unused.
Modified:
llvm/trunk/include/llvm/Support/MemoryBuffer.h
llvm/trunk/lib/Support/MemoryBuffer.cpp
llvm/trunk/unittests/Support/MemoryBufferTest.cpp
Modified: llvm/trunk/include/llvm/Support/MemoryBuffer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MemoryBuffer.h?rev=321257&r1=321256&r2=321257&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/MemoryBuffer.h (original)
+++ llvm/trunk/include/llvm/Support/MemoryBuffer.h Thu Dec 21 03:27:21 2017
@@ -123,15 +123,6 @@ public:
static std::unique_ptr<MemoryBuffer>
getNewMemBuffer(size_t Size, StringRef BufferName = "");
- /// Allocate a new MemoryBuffer of the specified size that is not initialized.
- /// Note that the caller should initialize the memory allocated by this
- /// method. The memory is owned by the MemoryBuffer object.
- //
- // TODO: Remove this and migrate callers to
- // WritableMemoryBuffer::getNewUninitMemBuffer
- static std::unique_ptr<MemoryBuffer>
- getNewUninitMemBuffer(size_t Size, const Twine &BufferName = "");
-
/// Read all of stdin into a file buffer, and return it.
static ErrorOr<std::unique_ptr<MemoryBuffer>> getSTDIN();
@@ -199,6 +190,9 @@ public:
getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
bool IsVolatile = false);
+ /// Allocate a new MemoryBuffer of the specified size that is not initialized.
+ /// Note that the caller should initialize the memory allocated by this
+ /// method. The memory is owned by the MemoryBuffer object.
static std::unique_ptr<WritableMemoryBuffer>
getNewUninitMemBuffer(size_t Size, const Twine &BufferName = "");
Modified: llvm/trunk/lib/Support/MemoryBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MemoryBuffer.cpp?rev=321257&r1=321256&r2=321257&view=diff
==============================================================================
--- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)
+++ llvm/trunk/lib/Support/MemoryBuffer.cpp Thu Dec 21 03:27:21 2017
@@ -140,17 +140,12 @@ MemoryBuffer::getMemBufferCopy(StringRef
}
std::unique_ptr<MemoryBuffer>
-MemoryBuffer::getNewUninitMemBuffer(size_t Size, const Twine &BufferName) {
- return WritableMemoryBuffer::getNewUninitMemBuffer(Size, BufferName);
-}
-
-std::unique_ptr<MemoryBuffer>
MemoryBuffer::getNewMemBuffer(size_t Size, StringRef BufferName) {
- std::unique_ptr<MemoryBuffer> SB = getNewUninitMemBuffer(Size, BufferName);
+ auto SB = WritableMemoryBuffer::getNewUninitMemBuffer(Size, BufferName);
if (!SB)
return nullptr;
- memset(const_cast<char*>(SB->getBufferStart()), 0, Size);
- return SB;
+ memset(SB->getBufferStart(), 0, Size);
+ return std::move(SB);
}
ErrorOr<std::unique_ptr<MemoryBuffer>>
Modified: llvm/trunk/unittests/Support/MemoryBufferTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/MemoryBufferTest.cpp?rev=321257&r1=321256&r2=321257&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/MemoryBufferTest.cpp (original)
+++ llvm/trunk/unittests/Support/MemoryBufferTest.cpp Thu Dec 21 03:27:21 2017
@@ -104,15 +104,15 @@ TEST_F(MemoryBufferTest, copy) {
TEST_F(MemoryBufferTest, make_new) {
// 0-sized buffer
- OwningBuffer Zero(MemoryBuffer::getNewUninitMemBuffer(0));
+ OwningBuffer Zero(WritableMemoryBuffer::getNewUninitMemBuffer(0));
EXPECT_TRUE(nullptr != Zero.get());
// uninitialized buffer with no name
- OwningBuffer One(MemoryBuffer::getNewUninitMemBuffer(321));
+ OwningBuffer One(WritableMemoryBuffer::getNewUninitMemBuffer(321));
EXPECT_TRUE(nullptr != One.get());
// uninitialized buffer with name
- OwningBuffer Two(MemoryBuffer::getNewUninitMemBuffer(123, "bla"));
+ OwningBuffer Two(WritableMemoryBuffer::getNewUninitMemBuffer(123, "bla"));
EXPECT_TRUE(nullptr != Two.get());
// 0-initialized buffer with no name
More information about the llvm-commits
mailing list