diff options
author | Pavel Labath <labath@google.com> | 2017-12-21 11:27:21 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2017-12-21 11:27:21 +0000 |
commit | f13411ee9881c41c6eca81160a531b3bc8e62069 (patch) | |
tree | 9c0b32d72246ed67c29056ecc5611eaede0c7742 | |
parent | 98727bc26124b06207be869306f32179b25eace0 (diff) | |
download | bcm5719-llvm-f13411ee9881c41c6eca81160a531b3bc8e62069.tar.gz bcm5719-llvm-f13411ee9881c41c6eca81160a531b3bc8e62069.zip |
[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.
llvm-svn: 321257
-rw-r--r-- | llvm/include/llvm/Support/MemoryBuffer.h | 12 | ||||
-rw-r--r-- | llvm/lib/Support/MemoryBuffer.cpp | 11 | ||||
-rw-r--r-- | llvm/unittests/Support/MemoryBufferTest.cpp | 6 |
3 files changed, 9 insertions, 20 deletions
diff --git a/llvm/include/llvm/Support/MemoryBuffer.h b/llvm/include/llvm/Support/MemoryBuffer.h index 921d428b9b2..7b849fdb867 100644 --- a/llvm/include/llvm/Support/MemoryBuffer.h +++ b/llvm/include/llvm/Support/MemoryBuffer.h @@ -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 = ""); diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp index 8a93f97930c..c709fc416df 100644 --- a/llvm/lib/Support/MemoryBuffer.cpp +++ b/llvm/lib/Support/MemoryBuffer.cpp @@ -140,17 +140,12 @@ MemoryBuffer::getMemBufferCopy(StringRef InputData, const Twine &BufferName) { } 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>> diff --git a/llvm/unittests/Support/MemoryBufferTest.cpp b/llvm/unittests/Support/MemoryBufferTest.cpp index 0d9578621e0..5e3c8db0279 100644 --- a/llvm/unittests/Support/MemoryBufferTest.cpp +++ b/llvm/unittests/Support/MemoryBufferTest.cpp @@ -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 |