summaryrefslogtreecommitdiff
path: root/tools/llvm-bcanalyzer
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2016-11-02 00:08:19 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2016-11-02 00:08:19 +0000
commite8516587a2604386a8faaab28c410663c2ec884c (patch)
treee8b6fc5608214951fb388faf948200df8990a697 /tools/llvm-bcanalyzer
parenta0a6883ade4b400d4ed53048e877ca5711cded53 (diff)
Bitcode: Change reader interface to take memory buffers.
As proposed on llvm-dev: http://lists.llvm.org/pipermail/llvm-dev/2016-October/106595.html This change also fixes an API oddity where BitstreamCursor::Read() would return zero for the first read past the end of the bitstream, but would report_fatal_error for subsequent reads. Now we always report_fatal_error for all reads past the end. Updated clients to check for the end of the bitstream before reading from it. I also needed to add padding to the invalid bitcode tests in test/Bitcode/. This is because the streaming interface was not checking that the file size is a multiple of 4. Differential Revision: https://reviews.llvm.org/D26219 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285773 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-bcanalyzer')
-rw-r--r--tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp8
1 files changed, 2 insertions, 6 deletions
diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
index 96820f9c8a0..fec11e35d50 100644
--- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
+++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
@@ -436,10 +436,6 @@ static bool decodeMetadataStringsBlob(BitstreamReader &Reader, StringRef Indent,
SimpleBitstreamCursor R(Reader);
R.jumpToPointer(Lengths.begin());
- // Ensure that Blob doesn't get invalidated, even if this is reading from a
- // StreamingMemoryObject with corrupt data.
- R.setArtificialByteLimit(R.getCurrentByteNo() + StringsOffset);
-
StringRef Strings = Blob.drop_front(StringsOffset);
do {
if (R.AtEndOfStream())
@@ -735,7 +731,7 @@ static bool openBitcodeFile(StringRef Path,
return ReportError("Invalid bitcode wrapper header");
}
- StreamFile = BitstreamReader(BufPtr, EndBufPtr);
+ StreamFile = BitstreamReader(ArrayRef<uint8_t>(BufPtr, EndBufPtr));
Stream = BitstreamCursor(StreamFile);
StreamFile.CollectBlockInfoNames();
@@ -814,7 +810,7 @@ static int AnalyzeBitcode() {
if (Dump) outs() << "\n\n";
- uint64_t BufferSizeBits = StreamFile.getBitcodeBytes().getExtent() * CHAR_BIT;
+ uint64_t BufferSizeBits = StreamFile.getBitcodeBytes().size() * CHAR_BIT;
// Print a summary of the read file.
outs() << "Summary of " << InputFilename << ":\n";
outs() << " Total size: ";