Skip to content

Commit 21c303e

Browse files
committed
Fix undefined behavior when compiling in C++14 mode (with sized deletion
enabled): ensure that we do not invoke the sized deallocator for MemoryBuffer subclasses that have tail-allocated data. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259735 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 65ece99 commit 21c303e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/Support/MemoryBuffer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ class MemoryBufferMem : public MemoryBuffer {
8686
init(InputData.begin(), InputData.end(), RequiresNullTerminator);
8787
}
8888

89+
/// Disable sized deallocation for MemoryBufferMem, because it has
90+
/// tail-allocated data.
91+
void operator delete(void *p) { ::operator delete(p); }
92+
8993
const char *getBufferIdentifier() const override {
9094
// The name is stored after the class itself.
9195
return reinterpret_cast<const char*>(this + 1);
@@ -213,6 +217,10 @@ class MemoryBufferMMapFile : public MemoryBuffer {
213217
}
214218
}
215219

220+
/// Disable sized deallocation for MemoryBufferMMapFile, because it has
221+
/// tail-allocated data.
222+
void operator delete(void *p) { ::operator delete(p); }
223+
216224
const char *getBufferIdentifier() const override {
217225
// The name is stored after the class itself.
218226
return reinterpret_cast<const char *>(this + 1);

0 commit comments

Comments
 (0)