diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-06-16 20:03:39 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-06-16 20:03:39 +0000 |
commit | c6afe0d4e9e0da1398a71c50bd88fbd2c700c025 (patch) | |
tree | ddac8df1fe074402f6884491d5f9777a208fd7e9 /llvm/lib/Bitcode | |
parent | 76b080ac4d53bc44dca3efd0f39a5dbbac6fb792 (diff) | |
download | bcm5719-llvm-c6afe0d4e9e0da1398a71c50bd88fbd2c700c025.tar.gz bcm5719-llvm-c6afe0d4e9e0da1398a71c50bd88fbd2c700c025.zip |
Improve handling of end of file in the bitcode reader.
Before this patch the bitcode reader would read a module from a file
that contained in order:
* Any number of non MODULE_BLOCK sub blocks.
* One MODULE_BLOCK
* Any number of non MODULE_BLOCK sub blocks.
* 4 '\n' characters to handle OS X's ranlib.
Since we support lazy reading of modules, any information that is relevant
for the module has to be in the MODULE_BLOCK or before it. We don't gain
anything from checking what is after.
This patch then changes the reader to stop once the MODULE_BLOCK has been
successfully parsed.
This avoids the ugly special case for .bc files in an archive and makes it
easier to embed bitcode files.
llvm-svn: 239845
Diffstat (limited to 'llvm/lib/Bitcode')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 45 |
1 files changed, 5 insertions, 40 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 51973eb87fb..a4488ae05ab 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -3079,7 +3079,7 @@ std::error_code BitcodeReader::parseModule(bool Resume, std::error_code BitcodeReader::parseBitcodeInto(Module *M, bool ShouldLazyLoadMetadata) { - TheModule = nullptr; + TheModule = M; if (std::error_code EC = initStream()) return EC; @@ -3097,8 +3097,6 @@ std::error_code BitcodeReader::parseBitcodeInto(Module *M, // need to understand them all. while (1) { if (Stream.AtEndOfStream()) { - if (TheModule) - return std::error_code(); // We didn't really read a proper Module. return error("Malformed IR file"); } @@ -3106,47 +3104,14 @@ std::error_code BitcodeReader::parseBitcodeInto(Module *M, BitstreamEntry Entry = Stream.advance(BitstreamCursor::AF_DontAutoprocessAbbrevs); - switch (Entry.Kind) { - case BitstreamEntry::Error: + if (Entry.Kind != BitstreamEntry::SubBlock) return error("Malformed block"); - case BitstreamEntry::EndBlock: - return std::error_code(); - - case BitstreamEntry::SubBlock: - switch (Entry.ID) { - case bitc::BLOCKINFO_BLOCK_ID: - if (Stream.ReadBlockInfoBlock()) - return error("Malformed block"); - break; - case bitc::MODULE_BLOCK_ID: - // Reject multiple MODULE_BLOCK's in a single bitstream. - if (TheModule) - return error("Invalid multiple blocks"); - TheModule = M; - if (std::error_code EC = parseModule(false, ShouldLazyLoadMetadata)) - return EC; - if (Streamer) - return std::error_code(); - break; - default: - if (Stream.SkipBlock()) - return error("Invalid record"); - break; - } - continue; - case BitstreamEntry::Record: - // There should be no records in the top-level of blocks. - // The ranlib in Xcode 4 will align archive members by appending newlines - // to the end of them. If this file size is a multiple of 4 but not 8, we - // have to read and ignore these final 4 bytes :-( - if (Stream.getAbbrevIDWidth() == 2 && Entry.ID == 2 && - Stream.Read(6) == 2 && Stream.Read(24) == 0xa0a0a && - Stream.AtEndOfStream()) - return std::error_code(); + if (Entry.ID == bitc::MODULE_BLOCK_ID) + return parseModule(false, ShouldLazyLoadMetadata); + if (Stream.SkipBlock()) return error("Invalid record"); - } } } |