summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/FileOutputBuffer.cpp
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2019-05-20 20:53:05 +0000
committerLang Hames <lhames@gmail.com>2019-05-20 20:53:05 +0000
commit93d2bdda6bfe287de7825cfac9224dcfe051b1c5 (patch)
tree7b876090b9f6357dc81e5c09f63addfe0993e528 /llvm/lib/Support/FileOutputBuffer.cpp
parent52fa90a348c1bed5ecbcc0965c57d67e5ec45d5a (diff)
downloadbcm5719-llvm-93d2bdda6bfe287de7825cfac9224dcfe051b1c5.tar.gz
bcm5719-llvm-93d2bdda6bfe287de7825cfac9224dcfe051b1c5.zip
[Support] Renamed member 'Size' to 'AllocatedSize' in MemoryBlock and OwningMemoryBlock.
Rename member 'Size' to 'AllocatedSize' in order to provide a hint that the allocated size may be different than the requested size. Comments are added to clarify this point. Updated the InMemoryBuffer in FileOutputBuffer.cpp to track the requested buffer size. Patch by Machiel van Hooren. Thanks Machiel! https://reviews.llvm.org/D61599 llvm-svn: 361195
Diffstat (limited to 'llvm/lib/Support/FileOutputBuffer.cpp')
-rw-r--r--llvm/lib/Support/FileOutputBuffer.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp
index b0b817b4bdd..19ab2e9917a 100644
--- a/llvm/lib/Support/FileOutputBuffer.cpp
+++ b/llvm/lib/Support/FileOutputBuffer.cpp
@@ -75,20 +75,22 @@ private:
// output file on commit(). This is used only when we cannot use OnDiskBuffer.
class InMemoryBuffer : public FileOutputBuffer {
public:
- InMemoryBuffer(StringRef Path, MemoryBlock Buf, unsigned Mode)
- : FileOutputBuffer(Path), Buffer(Buf), Mode(Mode) {}
+ InMemoryBuffer(StringRef Path, MemoryBlock Buf, std::size_t BufSize,
+ unsigned Mode)
+ : FileOutputBuffer(Path), Buffer(Buf), BufferSize(BufSize),
+ Mode(Mode) {}
uint8_t *getBufferStart() const override { return (uint8_t *)Buffer.base(); }
uint8_t *getBufferEnd() const override {
- return (uint8_t *)Buffer.base() + Buffer.size();
+ return (uint8_t *)Buffer.base() + BufferSize;
}
- size_t getBufferSize() const override { return Buffer.size(); }
+ size_t getBufferSize() const override { return BufferSize; }
Error commit() override {
if (FinalPath == "-") {
- llvm::outs() << StringRef((const char *)Buffer.base(), Buffer.size());
+ llvm::outs() << StringRef((const char *)Buffer.base(), BufferSize);
llvm::outs().flush();
return Error::success();
}
@@ -100,12 +102,14 @@ public:
openFileForWrite(FinalPath, FD, CD_CreateAlways, OF_None, Mode))
return errorCodeToError(EC);
raw_fd_ostream OS(FD, /*shouldClose=*/true, /*unbuffered=*/true);
- OS << StringRef((const char *)Buffer.base(), Buffer.size());
+ OS << StringRef((const char *)Buffer.base(), BufferSize);
return Error::success();
}
private:
+ // Buffer may actually contain a larger memory block than BufferSize
OwningMemoryBlock Buffer;
+ size_t BufferSize;
unsigned Mode;
};
} // namespace
@@ -117,7 +121,7 @@ createInMemoryBuffer(StringRef Path, size_t Size, unsigned Mode) {
Size, nullptr, sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC);
if (EC)
return errorCodeToError(EC);
- return llvm::make_unique<InMemoryBuffer>(Path, MB, Mode);
+ return llvm::make_unique<InMemoryBuffer>(Path, MB, Size, Mode);
}
static Expected<std::unique_ptr<FileOutputBuffer>>
OpenPOWER on IntegriCloud