diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index b86d6e0..47957b4 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -27,6 +27,12 @@
 #include "llvm/OperandTraits.h"
 using namespace llvm;
 
+void BitcodeReader::getForwardReferencedFunctions(std::vector<Function*> &Fwd) {
+  for (BlockAddrRefMapTy::iterator I = BlockAddrFwdRefs.begin(),
+         E = BlockAddrFwdRefs.end(); I != E; ++I)
+    Fwd.push_back(I->first);
+}
+
 void BitcodeReader::FreeState() {
   if (BufferOwned)
     delete Buffer;
@@ -2779,6 +2785,15 @@ Module *llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
   }
   // Have the BitcodeReader dtor delete 'Buffer'.
   R->setBufferOwned(true);
+
+  std::vector<Function*> Fwd;
+  R->getForwardReferencedFunctions(Fwd);
+  for (std::vector<Function*>::iterator I = Fwd.begin(), E = Fwd.end();
+       I != E; ++I) {
+    Function *F = *I;
+    F->Materialize();
+  }
+
   return M;
 }
 
diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h
index 978b15b..86ae53c 100644
--- a/lib/Bitcode/Reader/BitcodeReader.h
+++ b/lib/Bitcode/Reader/BitcodeReader.h
@@ -173,7 +173,8 @@ class BitcodeReader : public GVMaterializer {
   /// BlockAddrFwdRefs - These are blockaddr references to basic blocks.  These
   /// are resolved lazily when functions are loaded.
   typedef std::pair<unsigned, GlobalVariable*> BlockAddrRefTy;
-  DenseMap<Function*, std::vector<BlockAddrRefTy> > BlockAddrFwdRefs;
+  typedef DenseMap<Function*, std::vector<BlockAddrRefTy> > BlockAddrRefMapTy;
+  BlockAddrRefMapTy BlockAddrFwdRefs;
 
 public:
   explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
@@ -184,7 +185,9 @@ public:
   ~BitcodeReader() {
     FreeState();
   }
-  
+
+  void getForwardReferencedFunctions(std::vector<Function*> &Fwd);
+
   void FreeState();
   
   /// setBufferOwned - If this is true, the reader will destroy the MemoryBuffer
