llvm.org GIT mirror llvm / 2a379e0
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321257 91177308-0d34-0410-b5e6-96231b3b80d8 Pavel Labath 2 years ago
3 changed file(s) with 9 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
122122 static std::unique_ptr
123123 getNewMemBuffer(size_t Size, StringRef BufferName = "");
124124
125 /// Allocate a new MemoryBuffer of the specified size that is not initialized.
126 /// Note that the caller should initialize the memory allocated by this
127 /// method. The memory is owned by the MemoryBuffer object.
128 //
129 // TODO: Remove this and migrate callers to
130 // WritableMemoryBuffer::getNewUninitMemBuffer
131 static std::unique_ptr
132 getNewUninitMemBuffer(size_t Size, const Twine &BufferName = "");
133
134125 /// Read all of stdin into a file buffer, and return it.
135126 static ErrorOr> getSTDIN();
136127
198189 getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
199190 bool IsVolatile = false);
200191
192 /// Allocate a new MemoryBuffer of the specified size that is not initialized.
193 /// Note that the caller should initialize the memory allocated by this
194 /// method. The memory is owned by the MemoryBuffer object.
201195 static std::unique_ptr
202196 getNewUninitMemBuffer(size_t Size, const Twine &BufferName = "");
203197
139139 }
140140
141141 std::unique_ptr
142 MemoryBuffer::getNewUninitMemBuffer(size_t Size, const Twine &BufferName) {
143 return WritableMemoryBuffer::getNewUninitMemBuffer(Size, BufferName);
144 }
145
146 std::unique_ptr
147142 MemoryBuffer::getNewMemBuffer(size_t Size, StringRef BufferName) {
148 std::unique_ptr SB = getNewUninitMemBuffer(Size, BufferName);
143 auto SB = WritableMemoryBuffer::getNewUninitMemBuffer(Size, BufferName);
149144 if (!SB)
150145 return nullptr;
151 memset(const_cast(SB->getBufferStart()), 0, Size);
152 return SB;
146 memset(SB->getBufferStart(), 0, Size);
147 return std::move(SB);
153148 }
154149
155150 ErrorOr>
103103
104104 TEST_F(MemoryBufferTest, make_new) {
105105 // 0-sized buffer
106 OwningBuffer Zero(MemoryBuffer::getNewUninitMemBuffer(0));
106 OwningBuffer Zero(WritableMemoryBuffer::getNewUninitMemBuffer(0));
107107 EXPECT_TRUE(nullptr != Zero.get());
108108
109109 // uninitialized buffer with no name
110 OwningBuffer One(MemoryBuffer::getNewUninitMemBuffer(321));
110 OwningBuffer One(WritableMemoryBuffer::getNewUninitMemBuffer(321));
111111 EXPECT_TRUE(nullptr != One.get());
112112
113113 // uninitialized buffer with name
114 OwningBuffer Two(MemoryBuffer::getNewUninitMemBuffer(123, "bla"));
114 OwningBuffer Two(WritableMemoryBuffer::getNewUninitMemBuffer(123, "bla"));
115115 EXPECT_TRUE(nullptr != Two.get());
116116
117117 // 0-initialized buffer with no name