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.
There is a semantic change here.
Previously, when at the end of the stream after calling Stream.advance(BitstreamCursor::AF_DontPopBlockAtEnd); we would call ReadCode() which would return 0 which is also bitc::END_BLOCK, and we would enter the condition below and return BitstreamEntry::getEndBlock();.
Now we return an error instead.
This is breaking the loop pattern in BitcodeReader::parseIdentificationBlock, which is conceptually the following: