Fix PR12080 by ensuring that MaterializeModule actually reads all the bitcode
authorDerek Schuff <dschuff@google.com>
Wed, 29 Feb 2012 00:07:09 +0000 (00:07 +0000)
committerDerek Schuff <dschuff@google.com>
Wed, 29 Feb 2012 00:07:09 +0000 (00:07 +0000)
in the streaming case.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151676 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Reader/BitcodeReader.h

index 899154971b8ef96b2b4f7a5dd7cc4744a8bdf030..e3990403bd71ba394f22c34965a8743a5cb910fc 100644 (file)
@@ -2789,6 +2789,12 @@ bool BitcodeReader::MaterializeModule(Module *M, std::string *ErrInfo) {
         Materialize(F, ErrInfo))
       return true;
 
+  // At this point, if there are any function bodies, the current bit is
+  // pointing to the END_BLOCK record after them. Now make sure the rest
+  // of the bits in the module have been read.
+  if (NextUnreadBit)
+    ParseModule(true);
+
   // Upgrade any intrinsic calls that slipped through (should not happen!) and
   // delete the old functions to clean up. We can't do this unless the entire
   // module is materialized because there could always be another function body
index ad7baa732da87ec23e1db421c3ce9a39aa9f11b9..e7c4e94f785f74862eae159ab21932fdee8b56f0 100644 (file)
@@ -182,13 +182,15 @@ class BitcodeReader : public GVMaterializer {
 public:
   explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
     : Context(C), TheModule(0), Buffer(buffer), BufferOwned(false),
-      LazyStreamer(0), SeenValueSymbolTable(false), ErrorString(0),
-      ValueList(C), MDValueList(C), SeenFirstFunctionBody(false) {
+      LazyStreamer(0), NextUnreadBit(0), SeenValueSymbolTable(false),
+      ErrorString(0), ValueList(C), MDValueList(C),
+      SeenFirstFunctionBody(false) {
   }
   explicit BitcodeReader(DataStreamer *streamer, LLVMContext &C)
     : Context(C), TheModule(0), Buffer(0), BufferOwned(false),
-      LazyStreamer(streamer), SeenValueSymbolTable(false), ErrorString(0),
-      ValueList(C), MDValueList(C), SeenFirstFunctionBody(false) {
+      LazyStreamer(streamer), NextUnreadBit(0), SeenValueSymbolTable(false),
+      ErrorString(0), ValueList(C), MDValueList(C),
+      SeenFirstFunctionBody(false) {
   }
   ~BitcodeReader() {
     FreeState();