[PATCH] Refactor bitcode reader to simplify control.

Karl Schimpf kschimpf at google.com
Mon Jun 1 13:51:34 PDT 2015


In addition to moving the code back in materializeModule, I fixed three tests. Two of them were fuzz tests where I "truncated" the file to the end of the module block. The other test did  not have anything after a bad abbreviation definition, and the code file was incomplete. So I generated a replacement test that was well structured otherwise (i.e. only had that one error in it).


================
Comment at: include/llvm/Bitcode/BitstreamReader.h:328
@@ -327,2 +327,3 @@
     if (BytesRead == 0) {
       Size = NextChar;
+      CurWord = 0;
----------------
This code fixes the state of the bit streamer when no more input is found. As a result, method AtEndOfStream now works correctly.

================
Comment at: lib/Bitcode/Reader/BitcodeReader.cpp:3226
@@ -3121,3 +3225,3 @@
     case BitstreamEntry::Error:
-      return Error("Malformed block");
     case BitstreamEntry::EndBlock:
+      {
----------------
Discovered that the Bitstream::EndBLock was "hiding" a bug int the bitstream reader when processing a data stream. That is, when using a data stream, the size is not set until after the eof is reached. Hence, when Stream.AtEndOfStream() was called above, it would return false even when at the eof. The actual problem was in FillCurWord, which did not set the bit position correctly when there was no more input.

The old code worked because the read (at eof) would return zero, and is understood as an end block. By returning success for this value, it would hide this problem.

I also improved the error message so that once can see where the reader thought the eof should be, if there is miscellaneous stuff at the end of the bit code file. This makes it easier to know where to cut a test file in such cases.

================
Comment at: lib/Bitcode/Reader/BitcodeReader.cpp:4657
@@ -4515,3 +4656,3 @@
 
   // Iterate over the module, deserializing any functions that are still on
   // disk.
----------------
Now that the eof checking is fixed, I moved this back where it was in an earlier version of this CL.

http://reviews.llvm.org/D8786

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list